CopperSpice DBUS  1.7.4
QDBusPendingCallWatcher Class Reference

Waits for asynchronous replies. More...

Inheritance diagram for QDBusPendingCallWatcher:
QDBusPendingCall

Public Signals

void finished (QDBusPendingCallWatcher *self=nullptr)
 

Public Methods

 QDBusPendingCallWatcher (const QDBusPendingCall &call, QObject *parent=nullptr)
 
 ~QDBusPendingCallWatcher ()
 
void waitForFinished ()
 
- Public Methods inherited from QDBusPendingCall
 QDBusPendingCall (const QDBusPendingCall &other)
 
 ~QDBusPendingCall ()
 
QDBusError error () const
 
bool isError () const
 
bool isFinished () const
 
bool isValid () const
 
QDBusPendingCall & operator= (const QDBusPendingCall &other)
 
QDBusPendingCall & operator= (QDBusPendingCall &&other) noexcept
 
QDBusMessage reply () const
 
void swap (QDBusPendingCall &other) noexcept
 
void waitForFinished ()
 

Additional Inherited Members

- Static Public Methods inherited from QDBusPendingCall
static QDBusPendingCall fromCompletedCall (const QDBusMessage &message)
 
static QDBusPendingCall fromError (const QDBusError &error)
 

Detailed Description

The QDBusPendingCallWatcher class provides a way to wait for asynchronous replies. The finished() signal is emitted when a reply arrives.

Example

The following example shows how to use this class.

QDBusPendingCall async = iface->asyncCall("RemoteMethod", value1, value2);
QObject::connect(watcher, &QDBusPendingCallWatcher::finished,
this, &DBus_PendingCall_Interface::callFinishedSlot);

The slot method callFinishedSlot referenced in the above call to connect() should be similar to the following. QDBusPendingReply is used to validate the argument types. If the reply does not contain a pair of arguments of the type QSting and QByteArray, then QDBusPendingReply::isError() will return true.

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

Constructor & Destructor Documentation

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

Creates a QDBusPendingCallWatcher object to watch for replies on the asynchronous pending call and then sets the parent of QDBusPendingCallWatcher to the given parent.

QDBusPendingCallWatcher::~QDBusPendingCallWatcher ( )

Destroys this object. If this QDBusPendingCallWatcher object was the last reference to the unfinished pending call, the call will be canceled.

Method Documentation

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

This signal is emitted when the pending call has finished and its reply is available. The self parameter is a pointer to the object itself, passed for convenience so that the slot can access the properties and determine the contents of the reply.

void QDBusPendingCallWatcher::waitForFinished ( )

Suspends the execution of the calling thread until the reply is received and processed. After this function returns, isFinished() should return true, indicating the reply's contents are ready to be processed.

See also
QDBusPendingCall::waitForFinished()