Couldn't received service registered signal when using QDBusServiceWatcher.

  • Hi all,
    I tried bellow code:

    void DbusWatcher::initDbus(QString service, QString path)
        QDBusConnection bus = QDBusConnection::sessionBus();
        if (bus.isConnected())
            qDebug() << "Dbus connected";
            QDBusServiceWatcher watcher(service, bus, QDBusServiceWatcher::WatchForRegistration);
            connect(&watcher, SIGNAL(serviceRegistered(QString)), this, SLOT(slotServiceRegistered(QString)));
            if (!bus.registerService(service))
                qDebug() << "Error register Service";
            if (!bus.registerObject(path,this))
                qDebug() << "Error register ObjectPath";
    void DbusWatcher::slotServiceRegistered(const QString service)
        qDebug() << "serviceRegister: " << service;

    My main.cpp file:

    #define SERVICE_NAME        ""
    #define OBJECT_PATH         "/com/abc/AppTest"
    int main(int argc, char *argv[])
        QGuiApplication app(argc, argv);
        DbusWatcher myTest;
        myTest.initDbus(SERVICE_NAME, OBJECT_PATH);
        return app.exec();

    I expect that when service is registered, Dbus will emit serviceRegistered signal. But when I ran this application, I didn't see any log text like "serviceRegister: " in slotServiceRegistered(). So what's wrong in this code? Thanks a lot :)

  • I have found solution for this, using QDbusConnectionInterface instead QDbusServiceWatcher:

    connect(QDBusConnection::sessionBus().interface(), &QDBusConnectionInterface::serviceRegistered, this, [=](QString a) {
                qDebug() <<"service R: " << a;

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.