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 イベントが発生した場合にのみ状態を変更することに注意してください。
QDBusPendingReply::isFinished()も参照 。
void QDBusPendingCallWatcher::waitForFinished()
応答を受信して処理するまで、呼び出し元のスレッドの実行を一時停止する。この関数が戻った後、isFinished() は真を返すはずである。これは、リプライの内容を処理する準備ができたことを示す。
QDBusPendingReply::waitForFinished()も参照のこと 。
© 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.