このページでは

QDBusPendingCallWatcher Class

QDBusPendingCallWatcher クラスは、非同期の応答を待機するための便利な方法を提供します。詳細...

ヘッダー: #include <QDBusPendingCallWatcher>
CMake: find_package(Qt6 REQUIRED COMPONENTS DBus)
target_link_libraries(mytarget PRIVATE Qt6::DBus)
qmake: QT += dbus
継承元:QObject およびQDBusPendingCall

パブリック関数

QDBusPendingCallWatcher(const QDBusPendingCall &call, QObject *parent = nullptr)
virtual ~QDBusPendingCallWatcher()
bool isFinished() const
void waitForFinished()

シグナル

void finished(QDBusPendingCallWatcher *self = nullptr)

詳細な説明

QDBusPendingCallWatcher は、応答が到着したときに発信される `finished()` シグナルを提供します。

通常、以下の例のように使用されます。

    QDBusPendingCall async = iface->asyncCall("RemoteMethod", value1, value2);
    QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this);

    QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this,
                     &DBus_PendingCall_Interface::callFinishedSlot);

QDBusPendingCallWatcher もそのクラスを継承しているため、元の `QDBusPendingCall ` オブジェクトを保持しておく必要はありません。

上記のコードで接続されているスロットは、次のようなものになるでしょう:

void DBus_PendingCall_Interface::callFinishedSlot(QDBusPendingCallWatcher *call)
{
    QDBusPendingReply<QString, QByteArray> reply = *call;
    if (reply.isError()) {
        showError();
    } else {
        QString text = reply.argumentAt<0>();
        QByteArray data = reply.argumentAt<1>();
        showReply(text, data);
    }
    call->deleteLater();
}

返信内の引数の型を検証するためにQDBusPendingReply が使用されている点に注意してください。返信に正確に2つの引数(1つの文字列と1つのQByteArray )が含まれていない場合、QDBusPendingReply::isError()はtrueを返します。

QDBusPendingReplyも参照してください 。

メンバ関数のドキュメント

[explicit] QDBusPendingCallWatcher::QDBusPendingCallWatcher(const QDBusPendingCall &call, QObject *parent = nullptr)

非同期の保留中の呼び出し `call ` に対する応答を監視するための `QDBusPendingCallWatcher` オブジェクトを作成し、このオブジェクトの親を `parent` に設定します。

[virtual noexcept] QDBusPendingCallWatcher::~QDBusPendingCallWatcher()

このオブジェクトを破棄します。この `QDBusPendingCallWatcher ` オブジェクトが、未完了の保留中の呼び出しに対する最後の参照であった場合、その呼び出しはキャンセルされます。

[signal] void QDBusPendingCallWatcher::finished(QDBusPendingCallWatcher *self = nullptr)

このシグナルは、保留中の呼び出しが終了し、その応答が利用可能になったときに発せられます。self パラメータは、オブジェクト自体へのポインタであり、スロットがそのプロパティにアクセスして応答の内容を確認できるように、便宜上渡されます。

bool QDBusPendingCallWatcher::isFinished() const

保留中の呼び出しの処理が完了し、応答を受信した場合は、true を返します。

なお、この関数は、waitForFinished() を呼び出した場合、または外部の D-Bus イベントが発生した場合にのみ状態が変更されます。外部の D-Bus イベントの発生は、一般的にイベントループの実行に戻った場合にのみ発生します。

QDBusPendingReply::isFinished()も参照してください 。

void QDBusPendingCallWatcher::waitForFinished()

応答を受信し、処理が完了するまで、呼び出し元のスレッドの実行を一時停止します。この関数が返った後、isFinished() は true を返すはずであり、これは応答の内容が処理可能な状態になったことを示します。

QDBusPendingReply::waitForFinished()も参照してください 。

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