diff --git a/src/dbus/qdbusabstractinterface.cpp b/src/dbus/qdbusabstractinterface.cpp index 53def1beb6..0b584963ee 100644 --- a/src/dbus/qdbusabstractinterface.cpp +++ b/src/dbus/qdbusabstractinterface.cpp @@ -288,7 +288,8 @@ QDBusAbstractInterface::QDBusAbstractInterface(QDBusAbstractInterfacePrivate &d, if (d.isValid && d.connection.isConnected() && !d.service.isEmpty() - && !d.service.startsWith(QLatin1Char(':'))) + && !d.service.startsWith(QLatin1Char(':')) + && d.connectionPrivate()->mode != QDBusConnectionPrivate::PeerMode) d_func()->connection.connect(QLatin1String(DBUS_SERVICE_DBUS), // service QString(), // path QLatin1String(DBUS_INTERFACE_DBUS), // interface @@ -313,7 +314,8 @@ QDBusAbstractInterface::QDBusAbstractInterface(const QString &service, const QSt if (d_func()->isValid && d_func()->connection.isConnected() && !service.isEmpty() - && !service.startsWith(QLatin1Char(':'))) + && !service.startsWith(QLatin1Char(':')) + && d_func()->connectionPrivate()->mode != QDBusConnectionPrivate::PeerMode) d_func()->connection.connect(QLatin1String(DBUS_SERVICE_DBUS), // service QString(), // path QLatin1String(DBUS_INTERFACE_DBUS), // interface @@ -340,7 +342,13 @@ QDBusAbstractInterface::~QDBusAbstractInterface() */ bool QDBusAbstractInterface::isValid() const { - return !d_func()->currentOwner.isEmpty(); + Q_D(const QDBusAbstractInterface); + /* We don't retrieve the owner name for peer connections */ + if (d->connectionPrivate() && d->connectionPrivate()->mode == QDBusConnectionPrivate::PeerMode) { + return d->isValid; + } else { + return !d->currentOwner.isEmpty(); + } } /*! diff --git a/tests/auto/dbus/qdbusabstractinterface/tst_qdbusabstractinterface.cpp b/tests/auto/dbus/qdbusabstractinterface/tst_qdbusabstractinterface.cpp index 308e12b9ab..5f3cf539e9 100644 --- a/tests/auto/dbus/qdbusabstractinterface/tst_qdbusabstractinterface.cpp +++ b/tests/auto/dbus/qdbusabstractinterface/tst_qdbusabstractinterface.cpp @@ -70,12 +70,12 @@ class tst_QDBusAbstractInterface: public QObject return Pinger(new com::trolltech::QtDBus::Pinger(service, path, con)); } - Pinger getPingerPeer(const QString &path = "/") + Pinger getPingerPeer(const QString &path = "/", const QString &service = "") { QDBusConnection con = QDBusConnection("peer"); if (!con.isConnected()) return Pinger(); - return Pinger(new com::trolltech::QtDBus::Pinger("", path, con)); + return Pinger(new com::trolltech::QtDBus::Pinger(service, path, con)); } void resetServer() @@ -197,6 +197,10 @@ private slots: void directPropertyReadErrorsPeer(); void directPropertyWriteErrorsPeer_data(); void directPropertyWriteErrorsPeer(); + + void validity_data(); + void validity(); + private: QProcess proc; }; @@ -1381,5 +1385,23 @@ void tst_QDBusAbstractInterface::directPropertyWriteErrorsPeer() QTEST(p->lastError().name(), "errorName"); } +void tst_QDBusAbstractInterface::validity_data() +{ + QTest::addColumn("service"); + + QTest::newRow("null-service") << ""; + QTest::newRow("ignored-service") << "org.example.anyservice"; +} + +void tst_QDBusAbstractInterface::validity() +{ + /* Test case for QTBUG-32374 */ + QFETCH(QString, service); + Pinger p = getPingerPeer("/", service); + QVERIFY2(p, "Not connected to D-Bus"); + + QVERIFY(p->isValid()); +} + QTEST_MAIN(tst_QDBusAbstractInterface) #include "tst_qdbusabstractinterface.moc"