QDBusPendingCallWatcher Class
La classe QDBusPendingCallWatcher fournit un moyen pratique d'attendre des réponses asynchrones. Plus d'informations...
| En-tête : | #include <QDBusPendingCallWatcher> |
| CMake : | find_package(Qt6 REQUIRED COMPONENTS DBus)target_link_libraries(mytarget PRIVATE Qt6::DBus) |
| qmake : | QT += dbus |
| Hérite : | QObject et QDBusPendingCall |
Fonctions publiques
| QDBusPendingCallWatcher(const QDBusPendingCall &call, QObject *parent = nullptr) | |
| virtual | ~QDBusPendingCallWatcher() |
| bool | isFinished() const |
| void | waitForFinished() |
Signaux
| void | finished(QDBusPendingCallWatcher *self = nullptr) |
Description détaillée
Le QDBusPendingCallWatcher fournit le signal finished() qui sera émis lorsqu'une réponse arrivera.
Il est généralement utilisé comme dans l'exemple suivant :
QDBusPendingCall async = iface->asyncCall("RemoteMethod", value1, value2); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, &DBus_PendingCall_Interface::callFinishedSlot);
Notez qu'il n'est pas nécessaire de conserver l'objet original QDBusPendingCall puisque QDBusPendingCallWatcher hérite également de cette classe.
Le slot connecté par le code ci-dessus pourrait être similaire à ce qui suit :
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(); }
Notez l'utilisation de QDBusPendingReply pour valider les types d'arguments dans la réponse. Si la réponse ne contient pas exactement deux arguments (une chaîne et un QByteArray), QDBusPendingReply::isError() renverra true.
Voir également QDBusPendingReply.
Documentation sur les fonctions membres
[explicit] QDBusPendingCallWatcher::QDBusPendingCallWatcher(const QDBusPendingCall &call, QObject *parent = nullptr)
Crée un objet QDBusPendingCallWatcher pour surveiller les réponses à l'appel asynchrone en attente call et définit le parent de cet objet à parent.
[virtual noexcept] QDBusPendingCallWatcher::~QDBusPendingCallWatcher()
Détruit cet objet. Si cet objet QDBusPendingCallWatcher était la dernière référence à l'appel en attente inachevé, l'appel sera annulé.
[signal] void QDBusPendingCallWatcher::finished(QDBusPendingCallWatcher *self = nullptr)
Ce signal est émis lorsque l'appel en attente est terminé et que sa réponse est disponible. Le paramètre self est un pointeur sur l'objet lui-même, transmis par commodité afin que le slot puisse accéder aux propriétés et déterminer le contenu de la réponse.
bool QDBusPendingCallWatcher::isFinished() const
Renvoie true si le traitement de l'appel en attente est terminé et si la réponse a été reçue.
Notez que cette fonction ne change d'état que si vous appelez waitForFinished() ou si un événement D-Bus externe se produit, ce qui, en général, ne se produit que si vous revenez à l'exécution de la boucle d'événements.
Voir aussi QDBusPendingReply::isFinished().
void QDBusPendingCallWatcher::waitForFinished()
Suspend l'exécution du thread appelant jusqu'à ce que la réponse soit reçue et traitée. Après le retour de cette fonction, isFinished() doit renvoyer vrai, indiquant que le contenu de la réponse est prêt à être traité.
Voir également 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.