From dc131e3a5378d84026941e6626db524688b988f4 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 11 Jan 2013 11:25:28 -0800 Subject: Make QDBusPendingReply behave like QDBusReply when dealing with errors QDBusReply allows one to extract a QVariant and the type reply from an error reply and getting a default-constructed value. This is useful when a valid reply can never contain the default-constructed value (0, false, empty strings, empty arrays, etc.), so it simplifies error checking. More importantly, qdbusxml2cpp was changed a while ago from generating QDBusReply to generating QDBusPendingReply, so we need to have the same behavior. Task-number: QTBUG-29046 Change-Id: Ia873b9fd4311c0d4e94f0ef623ba405c20bc0e8c Reviewed-by: Olivier Goffart --- src/dbus/qdbuspendingreply.cpp | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'src/dbus/qdbuspendingreply.cpp') diff --git a/src/dbus/qdbuspendingreply.cpp b/src/dbus/qdbuspendingreply.cpp index 3d63c6a7fa..97d1b21a75 100644 --- a/src/dbus/qdbuspendingreply.cpp +++ b/src/dbus/qdbuspendingreply.cpp @@ -185,6 +185,11 @@ function's return value is undefined (will probably cause an assertion failure), so it is important to verify that the processing is finished and the reply is valid. + + If the reply does not contain an argument at position \a index or if the + reply was an error, this function returns an invalid QVariant. Since D-Bus + messages can never contain invalid QVariants, this return can be used to + detect an error condition. */ /*! @@ -197,6 +202,11 @@ Note that, if the reply hasn't arrived, this function causes the calling thread to block until the reply is processed. + + If the reply does not contain an argument at position \c Index or if the + reply was an error, this function returns a \c Type object that is default + constructed, which may be indistinguishable from a valid value. To reliably + determine whether the message was an error, use isError(). */ /*! @@ -211,6 +221,10 @@ Note that, if the reply hasn't arrived, this function causes the calling thread to block until the reply is processed. + + If the reply is an error reply, this function returns a default-constructed + \c T1 object, which may be indistinguishable from a valid value. To + reliably determine whether the message was an error, use isError(). */ /*! @@ -225,6 +239,10 @@ Note that, if the reply hasn't arrived, this function causes the calling thread to block until the reply is processed. + + If the reply is an error reply, this function returns a default-constructed + \c T1 object, which may be indistinguishable from a valid value. To + reliably determine whether the message was an error, use isError(). */ /*! @@ -260,14 +278,12 @@ void QDBusPendingReplyData::assign(const QDBusMessage &message) QVariant QDBusPendingReplyData::argumentAt(int index) const { - if (d) - d->waitForFinished(); // bypasses "const" + if (!d) + return QVariant(); - Q_ASSERT_X(d && index >= 0 && index < d->replyMessage.arguments().count(), - "QDBusPendingReply::argumentAt", - "Index out of bounds"); + d->waitForFinished(); // bypasses "const" - return d->replyMessage.arguments().at(index); + return d->replyMessage.arguments().value(index); } void QDBusPendingReplyData::setMetaTypes(int count, const int *types) -- cgit v1.2.3