Details
-
Bug
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
6.8.3, 6.9.0
-
None
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.