QDBusPendingCallWatcher Class
The QDBusPendingCallWatcher class provides a convenient way for waiting for asynchronous replies. More...
Header: | #include <QDBusPendingCallWatcher> |
qmake: | QT += dbus |
Since: | Qt 4.5 |
Inherits: | QObject and QDBusPendingCall |
This class was introduced in Qt 4.5.
Public Functions
QDBusPendingCallWatcher(const QDBusPendingCall &call, QObject *parent = nullptr) | |
virtual | ~QDBusPendingCallWatcher() |
- 16 public functions inherited from QObject
- 1 public function inherited from QDBusPendingCall
Related Non-Members
typedef | QObjectList |
Macros
QT_NO_NARROWING_CONVERSIONS_IN_CONNECT | |
Q_CLASSINFO(Name, Value) | |
Q_DISABLE_COPY(Class) | |
Q_DISABLE_COPY_MOVE(Class) | |
Q_DISABLE_MOVE(Class) | |
Q_EMIT | |
Q_ENUM(...) | |
Q_ENUM_NS(...) | |
Q_FLAG(...) | |
Q_FLAG_NS(...) | |
Q_GADGET | |
Q_INTERFACES(...) | |
Q_INVOKABLE | |
Q_NAMESPACE | |
Q_OBJECT | |
Q_PROPERTY(...) | |
Q_REVISION | |
Q_SET_OBJECT_NAME(Object) | |
Q_SIGNAL | |
Q_SIGNALS | |
Q_SLOT | |
Q_SLOTS |
Additional Inherited Members
- 1 property inherited from QObject
- 1 public slot inherited from QObject
- 1 signal inherited from QObject
- 5 static public members inherited from QObject
- 2 static public members inherited from QDBusPendingCall
- 8 protected functions inherited from QObject
Detailed Description
The QDBusPendingCallWatcher provides the finished() signal that will be emitted when a reply arrives.
It is usually used like the following example:
QDBusPendingCall async = iface->asyncCall("RemoteMethod", value1, value2); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(callFinishedSlot(QDBusPendingCallWatcher*)));
Note that it is not necessary to keep the original QDBusPendingCall object around since QDBusPendingCallWatcher inherits from that class too.
The slot connected to by the above code could be something similar to the following:
void MyClass::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(); }
Note the use of QDBusPendingReply to validate the argument types in the reply. If the reply did not contain exactly two arguments (one string and one QByteArray), QDBusPendingReply::isError() will return true.
See also QDBusPendingReply and QDBusAbstractInterface::asyncCall().
Member Function Documentation
QDBusPendingCallWatcher::QDBusPendingCallWatcher(const QDBusPendingCall &call, QObject *parent = nullptr)
Creates a QDBusPendingCallWatcher object to watch for replies on the asynchronous pending call call and sets this object's parent to parent.
[virtual]
QDBusPendingCallWatcher::~QDBusPendingCallWatcher()
Destroys this object. If this QDBusPendingCallWatcher object was the last reference to the unfinished pending call, the call will be canceled.