QDBusPendingReply Class▲
-
Header: QDBusPendingReply
-
Since: Qt 4.5
-
qmake: QT += dbus
Detailed Description▲
The QDBusPendingReply is a template class with up to 8 template parameters. Those parameters are the types that will be used to extract the contents of the reply's data.
This class is similar in functionality to QDBusReply, but with two important differences:
-
QDBusReply accepts exactly one return type, whereas QDBusPendingReply can have from 1 to 8 types
-
QDBusReply only works on already completed replies, whereas QDBusPendingReply allows one to wait for replies from pending calls
Where with QDBusReply you would write:
QDBusReply&
lt;QString&
gt; reply =
interface-&
gt;call("RemoteMethod"
);
if
(reply.isValid())
// use the returned value
useValue(reply.value());
else
// call failed. Show an error condition.
showError(reply.error());
with QDBusPendingReply, the equivalent code (including the blocking wait for the reply) would be:
QDBusPendingReply&
lt;QString&
gt; reply =
interface-&
gt;asyncCall("RemoteMethod"
);
reply.waitForFinished();
if
(reply.isError())
// call failed. Show an error condition.
showError(reply.error());
else
// use the returned value
useValue(reply.value());
For method calls that have more than one output argument, with QDBusReply, you would write:
QString reply =
interface-&
gt;call("RemoteMethod"
);
whereas with QDBusPendingReply, all of the output arguments should be template parameters:
QDBusPendingReply&
lt;bool
, QString&
gt; reply =
interface-&
gt;asyncCall("RemoteMethod"
);
reply.waitForFinished();
if
(!
reply.isError()) {
if
(reply.argumentAt&
lt;0
&
gt;())
showSuccess(reply.argumentAt&
lt;1
&
gt;());
else
showFailure(reply.argumentAt&
lt;1
&
gt;());
}
QDBusPendingReply objects can be associated with QDBusPendingCallWatcher objects, which emit signals when the reply arrives.
See Also▲
See also QDBusPendingCallWatcher, QDBusReply