From 624ee454ec58074c1156b8a82f48ba83279c44fa Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 11 Dec 2014 13:58:52 -0800 Subject: [PATCH] Make QDBusConnection and QDBusServer return an error on default objects The error of "Not connected". This incidentally solves a crash when QDBusServer().lastError() is called but libdbus-1 couldn't be found. Change-Id: Id93f447d00c0aa6660d4528c4bbce5998d9186a8 Reviewed-by: Alex Blasche --- src/dbus/qdbusconnection.cpp | 2 +- src/dbus/qdbusserver.cpp | 2 +- tests/auto/dbus/qdbusconnection/tst_qdbusconnection.cpp | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/dbus/qdbusconnection.cpp b/src/dbus/qdbusconnection.cpp index 1a56f53a63..a46df16ac5 100644 --- a/src/dbus/qdbusconnection.cpp +++ b/src/dbus/qdbusconnection.cpp @@ -959,7 +959,7 @@ bool QDBusConnection::isConnected() const */ QDBusError QDBusConnection::lastError() const { - return d ? d->lastError : QDBusError(); + return d ? d->lastError : QDBusError(QDBusError::Disconnected, QStringLiteral("Not connected.")); } /*! diff --git a/src/dbus/qdbusserver.cpp b/src/dbus/qdbusserver.cpp index 54b38ee848..b2c76a8750 100644 --- a/src/dbus/qdbusserver.cpp +++ b/src/dbus/qdbusserver.cpp @@ -129,7 +129,7 @@ bool QDBusServer::isConnected() const */ QDBusError QDBusServer::lastError() const { - return d->lastError; + return d ? d->lastError : QDBusError(QDBusError::Disconnected, QStringLiteral("Not connected.")); } /*! diff --git a/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.cpp b/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.cpp index 7e6e742e28..df6fb9e9bc 100644 --- a/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.cpp +++ b/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.cpp @@ -246,7 +246,7 @@ void tst_QDBusConnection::connectToBus() QDBusConnection con2("foo"); QVERIFY(!con2.isConnected()); - QVERIFY(!con2.lastError().isValid()); + QVERIFY(con2.lastError().isValid()); con2 = con; QVERIFY(con.isConnected()); @@ -274,7 +274,7 @@ void tst_QDBusConnection::connectToBus() { QDBusConnection con("bubu"); QVERIFY(!con.isConnected()); - QVERIFY(!con.lastError().isValid()); + QVERIFY(con.lastError().isValid()); } QByteArray address = qgetenv("DBUS_SESSION_BUS_ADDRESS"); @@ -314,7 +314,7 @@ void tst_QDBusConnection::connectToPeer() QDBusConnection con2("foo"); QVERIFY(!con2.isConnected()); - QVERIFY(!con2.lastError().isValid()); + QVERIFY(con2.lastError().isValid()); con2 = con; QVERIFY(con.isConnected()); @@ -342,7 +342,7 @@ void tst_QDBusConnection::connectToPeer() { QDBusConnection con("bubu"); QVERIFY(!con.isConnected()); - QVERIFY(!con.lastError().isValid()); + QVERIFY(con.lastError().isValid()); } }