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:

Where with QDBusReply you would write:

 
Sélectionnez
QDBusReply<QString> reply = interface->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:

 
Sélectionnez
    QDBusPendingReply<QString> reply = interface->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:

 
Sélectionnez
QString reply = interface->call("RemoteMethod");

whereas with QDBusPendingReply, all of the output arguments should be template parameters:

 
Sélectionnez
    QDBusPendingReply<bool, QString> reply = interface->asyncCall("RemoteMethod");
    reply.waitForFinished();
    if (!reply.isError()) {
        if (reply.argumentAt<0>())
            showSuccess(reply.argumentAt<1>());
        else
            showFailure(reply.argumentAt<1>());
    }

QDBusPendingReply objects can be associated with QDBusPendingCallWatcher objects, which emit signals when the reply arrives.

See Also

See also QDBusPendingCallWatcher, QDBusReply

Member Type Documentation

 

enum QDBusPendingReply::anonymous

Constant

Value