Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Couldn't received service registered signal when using QDBusServiceWatcher.

Couldn't received service registered signal when using QDBusServiceWatcher.

Scheduled Pinned Locked Moved Solved General and Desktop
dbus
2 Posts 1 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hieu Nguyen
    wrote on last edited by
    #1

    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        "com.abc.AppTest"
    #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 com.abc.AppTest 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 :)

    H 1 Reply Last reply
    0
    • H Hieu Nguyen

      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        "com.abc.AppTest"
      #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 com.abc.AppTest 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 :)

      H Offline
      H Offline
      Hieu Nguyen
      wrote on last edited by
      #2

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

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

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved