I'm trying to connect a slot to a signal emitted through DBus in PyQt 5.6 with Python 3.5.
When I run my script like this QDBUS_DEBUG=1 python3 qtdbustest.py
it never reaches the call to print('Connected')
but instead just hangs at the bus.connect(...)
call. The signal is seen on the bus as evident in the debug output:
QDBusConnectionPrivate(0x7f3e60002b00) : connected successfully QDBusConnectionPrivate(0x7f3e60002b00) got message (signal): QDBusMessage(type=Signal, service="org.freedesktop.DBus", path="/org/freedesktop/DBus", interface="org.freedesktop.DBus", member="NameAcquired", signature="s", contents=(":1.137") ) QDBusConnectionPrivate(0x7f3e60002b00) delivery is suspended
Here is my minimal working example:
#!/usr/bin/python3
import sys
from PyQt5.QtCore import QObject, pyqtSlot
from PyQt5.QtWidgets import QApplication
from PyQt5.QtDBus import QDBusConnection, QDBusMessage
class DbusTest(QObject):
def __init__(self):
super(DbusTest, self).__init__()
bus = QDBusConnection.systemBus()
bus.connect(
'org.freedesktop.DBus',
'/org/freedesktop/DBus',
'org.freedesktop.DBus',
'NameAcquired',
self.testMessage
)
print('Connected')
@pyqtSlot(QDBusMessage)
def testMessage(self, msg):
print(msg)
if __name__ == '__main__':
app = QApplication(sys.argv)
discoverer = DbusTest()
sys.exit(app.exec_())
What am I doing wrong? There must be something I overlooked so that the call to bus.connect(...)
actually returns.