diff options
-rw-r--r-- | src/dbus/qdbuspendingreply.cpp | 28 | ||||
-rw-r--r-- | src/dbus/qdbuspendingreply.h | 4 | ||||
-rw-r--r-- | tests/auto/dbus/qdbuspendingreply/tst_qdbuspendingreply.cpp | 7 |
3 files changed, 30 insertions, 9 deletions
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) diff --git a/src/dbus/qdbuspendingreply.h b/src/dbus/qdbuspendingreply.h index 47a82363db..6511d2df2c 100644 --- a/src/dbus/qdbuspendingreply.h +++ b/src/dbus/qdbuspendingreply.h @@ -168,9 +168,7 @@ public: template<int Index> inline const typename Select<Index>::Type argumentAt() const { - // static assert? - Q_ASSERT_X(Index < count() && Index >= 0, "QDBusPendingReply::argumentAt", - "Index out of bounds"); + Q_STATIC_ASSERT_X(Index >= 0 && Index < Count, "Index out of bounds"); typedef typename Select<Index>::Type ResultType; return qdbus_cast<ResultType>(argumentAt(Index), 0); } diff --git a/tests/auto/dbus/qdbuspendingreply/tst_qdbuspendingreply.cpp b/tests/auto/dbus/qdbuspendingreply/tst_qdbuspendingreply.cpp index e4863574e3..31b7e0dbce 100644 --- a/tests/auto/dbus/qdbuspendingreply/tst_qdbuspendingreply.cpp +++ b/tests/auto/dbus/qdbuspendingreply/tst_qdbuspendingreply.cpp @@ -572,6 +572,8 @@ void tst_QDBusPendingReply::errors() QVERIFY(rint.isError()); error = rint.error(); VERIFY_ERROR(error); + int dummyint = rint; + QCOMPARE(dummyint, int()); QDBusPendingReply<int,int> rintint(iface->asyncCall("sendError")); rintint.waitForFinished(); @@ -579,6 +581,9 @@ void tst_QDBusPendingReply::errors() QVERIFY(rintint.isError()); error = rintint.error(); VERIFY_ERROR(error); + dummyint = rintint; + QCOMPARE(dummyint, int()); + QCOMPARE(rintint.argumentAt<1>(), int()); QDBusPendingReply<QString> rstring(iface->asyncCall("sendError")); rstring.waitForFinished(); @@ -586,6 +591,8 @@ void tst_QDBusPendingReply::errors() QVERIFY(rstring.isError()); error = rstring.error(); VERIFY_ERROR(error); + QString dummystring = rstring; + QCOMPARE(dummystring, QString()); } QTEST_MAIN(tst_QDBusPendingReply) |