이 페이지에서

QDBusContext Class

QDBusContext 클래스를 사용하면 슬롯에서 호출의 D-Bus 컨텍스트를 파악할 수 있습니다. 더 보기...

헤더: #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 가 false인 경우, 호출된 슬롯이 반환되는 즉시 필요에 따라 Qt D-Bus 가 호출자에게 자동으로 응답을 생성합니다.

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

답장을 보내지 못하면 D-Bus에서 자동 타임아웃 오류가 발생합니다.

isDelayedReply()도 참조하십시오 .

© 2026 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.