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.
QtWS25 Last Chance

Couldn't received service registered signal when using QDBusServiceWatcher.

Scheduled Pinned Locked Moved Solved General and Desktop
dbus
2 Posts 1 Posters 921 Views
  • 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 25 Sept 2016, 12:36 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 25 Sept 2016, 14:06
    0
    • H Hieu Nguyen
      25 Sept 2016, 12:36

      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 25 Sept 2016, 14:06 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

      2/2

      25 Sept 2016, 14:06

      • Login

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