QDBusContext Class

QDBusContext 클래스는 슬롯이 호출의 D-Bus 컨텍스트를 결정할 수 있도록 합니다. 더 보기...

Header: #include <QDBusContext>
CMake: find_package(Qt6 REQUIRED COMPONENTS DBus)
target_link_libraries(mytarget PRIVATE Qt6::DBus)
qmake: QT += dbus

공용 함수

QDBusContext()
~QDBusContext()
bool calledFromDBus() const
QDBusConnection connection() const
bool isDelayedReply() const
const QDBusMessage &message() const
void sendErrorReply(const QString &name, const QString &msg = QString()) const
void sendErrorReply(QDBusError::ErrorType type, const QString &msg = QString()) const
void setDelayedReply(bool enable) const

자세한 설명

신호 전달이나 원격 메서드 호출로 인해 객체에서 슬롯이 호출될 때, 그 상황을 알아야 할 필요가 있을 때가 있습니다. 특히 슬롯이 나중에 응답을 보내기로 결정하거나 오류와 함께 응답하려는 경우 컨텍스트가 필요합니다.

QDBusContext 클래스는 Qt D-Bus XML 컴파일러(qdbusxml2cpp)에서 생성된 코드를 수정하지 않고도 컨텍스트에 액세스할 수 있는 대안입니다.

QDBusContext는 QDBusConnection::registerObject()를 사용하여 내보내는 객체에서 서브클래싱하여 사용합니다. 다음 예제는 사용법을 설명합니다:

class MyObject: public QObject,
                protected QDBusContext
{
    Q_OBJECT

    QDBusConnection conn;
    QDBusMessage msg;

    //...

protected slots:
    void process();
public slots:
    void methodWithError();
    QString methodWithDelayedReply();
};

void MyObject::methodWithError()
{
    sendErrorReply(QDBusError::NotSupported,
                   "The method call 'methodWithError()' is not supported");
}

QString MyObject::methodWithDelayedReply()
{
    conn = connection();
    msg = message();
    setDelayedReply(true);
    QMetaObject::invokeMethod(this, &MyObject::process, Qt::QueuedConnection);
    return QString();
}

이 예는 오류 회신을 보내는 것과 지연된 회신을 보내는 두 가지 일반적인 용도를 보여줍니다.

참고: QDBusContext와 QDBusAbstractAdaptor 를 동시에 서브클래싱하지 마세요. QDBusContext는 어댑터가 아닌 실제 객체에 나타나야 합니다. 어댑터 코드에서 컨텍스트를 확인해야 하는 경우 공용 상속을 사용하고 QObject::parent()를 통해 함수에 액세스하세요.

멤버 함수 문서

QDBusContext::QDBusContext()

빈 QDBusContext를 생성합니다.

[noexcept] QDBusContext::~QDBusContext()

빈 디스트럭터입니다.

bool QDBusContext::calledFromDBus() const

D-Bus 호출을 처리 중인 경우 true 을 반환합니다. 이 함수가 true 를 반환하면 이 클래스의 나머지 함수를 사용할 수 있습니다.

이 함수가 false 를 반환할 때 해당 함수에 액세스하면 정의되지 않은 함수가 되며 충돌이 발생할 수 있습니다.

QDBusConnection QDBusContext::connection() const

이 호출이 수신된 연결을 반환합니다.

bool QDBusContext::isDelayedReply() const

이 호출에 응답이 지연되면 true 을 반환합니다.

setDelayedReply()도 참조하세요 .

const QDBusMessage &QDBusContext::message() const

이 호출을 생성한 메시지를 반환합니다.

void QDBusContext::sendErrorReply(const QString &name, const QString &msg = QString()) const

오류 name 를 발신자에게 답장으로 보냅니다. 선택 사항인 msg 매개변수는 실패를 설명하는 사람이 읽을 수 있는 텍스트입니다.

오류가 전송되면 반환값과 호출된 슬롯의 모든 출력 매개변수는 Qt D-Bus 에 의해 무시됩니다.

void QDBusContext::sendErrorReply(QDBusError::ErrorType type, const QString &msg = QString()) const

이 함수는 과부하된 함수입니다.

호출자에게 응답으로 type 오류를 보냅니다. 선택적 msg 매개변수는 실패를 설명하는 사람이 읽을 수 있는 텍스트입니다.

오류가 전송되면 반환값과 호출된 슬롯의 모든 출력 매개변수는 Qt D-Bus 에 의해 무시됩니다.

void QDBusContext::setDelayedReply(bool enable) const

이 호출에 지연 회신 여부를 설정합니다.

enable 이 거짓인 경우 Qt D-Bus 은 호출된 슬롯이 반환되는 즉시 필요한 경우 발신자에게 자동으로 답장을 생성합니다.

enable 이 참이면 Qt D-Bus 은 자동 회신을 생성하지 않습니다. 또한 슬롯의 반환 값과 모든 출력 매개변수도 무시합니다. 대신 호출된 객체는 수신 메시지를 저장하고 나중에 회신 또는 오류를 전송할 책임이 있습니다.

응답을 보내지 못하면 D-Bus에서 자동 시간 초과 오류가 발생합니다.

isDelayedReply()도 참조하세요 .

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.