Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-135928

Connection to D-Bus signals silently breaks if D-Bus was used before creating QCoreApplication

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • 6.8.3, 6.9.0
    • D-Bus
    • None
    • Linux/Wayland

    Description

      If D-Bus is used (e.g. by synchronously calling some method) before creating Q(Core/Gui)Application, connecting to D-Bus signals (done after application is created) does nothing. Calling methods meanwhile continues to work.

      Sample code:

      #include <QCoreApplication>
      #include <QDBusConnection>
      #include <QDBusInterface>
      #include <QDebug>
      
      void ping() {
        QDBusInterface iface("org.freedesktop.DBus", "/",
                             "org.freedesktop.DBus.Peer");
        auto reply = iface.call("Ping");
        qInfo() << "ping" << reply;
      }
      
      class Receiver : public QObject {
        Q_OBJECT
      public slots:
        void received(const QDBusMessage &message) {
          qInfo() << "received signal" << message;
        }
      };
      
      int main(int argc, char *argv[]) {
        ping();
      
        QCoreApplication a(argc, argv);
      
        ping();
      
        auto receiver = new Receiver();
        QDBusConnection::sessionBus().connect({}, "/", "org.foo.bar", "Fooed",
                                              receiver, SLOT(received(QDBusMessage)));
      
        return a.exec();
      }
      
      #include "main.moc"
      

      Start this program, then run `dbus-send --session --type=signal / org.foo.bar.Fooed` in the terminal to send the signal. You will notice that "received signal" is not printed. If you remove first ping() call, then it works.

      It would be nice to at least have a runtime warning message in this case.

      Debugging revealed the issue is caused by the fact that QDBusConnectionPrivate::enableDispatchDelayed here is called with nullptr argument (which is probably an error since the comment says that "qApp was checked in the caller") which makes QDBusConnectionPrivate::enableDispatchDelayed not call QDBusConnectionPrivate::setDispatchEnabled.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            equeim Alexey
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes