summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/dbus/qdbusintegrator.cpp27
-rw-r--r--tests/auto/qdbusconnection/tst_qdbusconnection.cpp29
2 files changed, 38 insertions, 18 deletions
diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp
index 44abf7b..6cb4924 100644
--- a/src/dbus/qdbusintegrator.cpp
+++ b/src/dbus/qdbusintegrator.cpp
@@ -1937,7 +1937,7 @@ int QDBusConnectionPrivate::sendWithReplyAsync(const QDBusMessage &message, QObj
QDBusPendingCallPrivate *pcall = sendWithReplyAsync(message, timeout);
Q_ASSERT(pcall);
- // has it already finished (dispatched locally)?
+ // has it already finished with success (dispatched locally)?
if (pcall->replyMessage.type() == QDBusMessage::ReplyMessage) {
pcall->setReplyCallback(receiver, returnMethod);
processFinishedCall(pcall);
@@ -1945,33 +1945,24 @@ int QDBusConnectionPrivate::sendWithReplyAsync(const QDBusMessage &message, QObj
return 1;
}
+ // either it hasn't finished or it has finished with error
+ if (errorMethod) {
+ pcall->watcherHelper = new QDBusPendingCallWatcherHelper;
+ connect(pcall->watcherHelper, SIGNAL(error(QDBusError,QDBusMessage)), receiver, errorMethod,
+ Qt::QueuedConnection);
+ pcall->watcherHelper->moveToThread(thread());
+ }
+
// has it already finished and is an error reply message?
if (pcall->replyMessage.type() == QDBusMessage::ErrorMessage) {
- if (errorMethod) {
- pcall->watcherHelper = new QDBusPendingCallWatcherHelper;
- connect(pcall->watcherHelper, SIGNAL(error(QDBusError,QDBusMessage)), receiver, errorMethod);
- pcall->watcherHelper->moveToThread(thread());
- }
processFinishedCall(pcall);
delete pcall;
return 1;
}
- // has it already finished with error?
- if (pcall->replyMessage.type() != QDBusMessage::InvalidMessage) {
- delete pcall;
- return 0;
- }
-
pcall->autoDelete = true;
pcall->ref.ref();
-
pcall->setReplyCallback(receiver, returnMethod);
- if (errorMethod) {
- pcall->watcherHelper = new QDBusPendingCallWatcherHelper;
- connect(pcall->watcherHelper, SIGNAL(error(QDBusError,QDBusMessage)), receiver, errorMethod);
- pcall->watcherHelper->moveToThread(thread());
- }
return 1;
}
diff --git a/tests/auto/qdbusconnection/tst_qdbusconnection.cpp b/tests/auto/qdbusconnection/tst_qdbusconnection.cpp
index 5e2f3a9..96209b1 100644
--- a/tests/auto/qdbusconnection/tst_qdbusconnection.cpp
+++ b/tests/auto/qdbusconnection/tst_qdbusconnection.cpp
@@ -80,6 +80,8 @@ class tst_QDBusConnection: public QObject
int signalsReceived;
public slots:
void oneSlot() { ++signalsReceived; }
+ void exitLoop() { ++signalsReceived; QTestEventLoop::instance().exitLoop(); }
+ void secondCallWithCallback();
private slots:
void noConnection();
@@ -102,6 +104,7 @@ private slots:
void multipleInterfacesInQObject();
void slotsWithLessParameters();
+ void nestedCallWithCallback();
public:
QString serviceName() const { return "com.trolltech.Qt.Autotests.QDBusConnection"; }
@@ -618,6 +621,32 @@ void tst_QDBusConnection::slotsWithLessParameters()
QCOMPARE(signalsReceived, 1);
}
+void tst_QDBusConnection::secondCallWithCallback()
+{
+ qDebug("Hello");
+ QDBusConnection con = QDBusConnection::sessionBus();
+ QDBusMessage msg = QDBusMessage::createMethodCall(con.baseService(), "/test", QString(),
+ "test0");
+ con.callWithCallback(msg, this, SLOT(exitLoop()), SLOT(secondCallWithCallback()));
+}
+
+void tst_QDBusConnection::nestedCallWithCallback()
+{
+ TestObject testObject;
+ QDBusConnection connection = QDBusConnection::sessionBus();
+ QVERIFY(connection.registerObject("/test", &testObject,
+ QDBusConnection::ExportAllContents));
+
+ QDBusMessage msg = QDBusMessage::createMethodCall(connection.baseService(), "/test", QString(),
+ "ThisFunctionDoesntExist");
+ signalsReceived = 0;
+
+ connection.callWithCallback(msg, this, SLOT(exitLoop()), SLOT(secondCallWithCallback()), 10);
+ QTestEventLoop::instance().enterLoop(15);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+ QCOMPARE(signalsReceived, 1);
+}
+
QString MyObject::path;
QTEST_MAIN(tst_QDBusConnection)