I am implementing an interface to an embedded device which exposes its hardware configuration via a dbus API.
At the moment I work out the access to the hardware I/O-pins of the device. While configuring and reading/writing those pins works already as expected, I have problems to properly connect the PropertiesChanged signal for those input pins to a slot in my qt application. That signal is notifying listeners of changes to the present input value at that very pin.
When whatched via dbus-monitor
the signal for example looks like this:
signal sender=:1.2 -> dest=(null destination) serial=1023 path=/com/actia/platform/io/freq_in1_std; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
string "com.actia.platform.io.digital_input"
array [
dict entry(
string "InputValue"
variant int32 17857
)
]
array [
]
which represents the value of an applied frequency of 1.7857 kHz.
I connect to the signal like so:
if (QDBusConnection::sessionBus().connect("com.actia.platform.io", "/com/actia/platform/io/freq_in1_std",
"org.freedesktop.DBus.Properties", "PropertiesChanged", this,
SLOT(propertyChanged(QString, QVariantMap, QStringList)))) {
qDebug() << "PropertiesChanged signal connected successfully to slot";
} else {
qDebug() << "PropertiesChanged signal connection was not successful";
}
and the connected slot looks like:
void MyClass::propertyChanged(QString name, QVariantMap map, QStringList list)
{
qDebug() << QString("properties of interface %1 changed").arg(name);
for (QVariantMap::const_iterator it = map.cbegin(), end = map.cend(); it != end; ++it) {
qDebug() << "property: " << it.key() << " value: " << it.value();
}
for (const auto& element : list) {
qDebug() << "list element: " << element;
}
}
I see that the connection is done successfully but apparently something seems not to be right about the signature, I assume. Because I never see that slot called.
Here is an excerpt of the debug output with QDBUS_DEBUG=1
of a little example application class, where I instanciate one input and one output pin where I connect the PropertiesChanged signal and then access some of the dbus methods and properties manually, before leaving it idling to wait for the signal to catch. I commented that debug log a bit. After some time, when the signal on the dbus has been fired several times, I quit the application.
### application.debug: start of initialization before issuing QCoreApplication::exec()...
### application.debug: creating a digital out pin...
// comment on the logs: The folloiwing 6 lines of debug output originate of instanciating the matching dbus proxy that has been generated by qdbusxml2cpp
QDBusConnectionPrivate(0x747021d0) : connected successfully
QDBusConnectionPrivate(0x747021d0) got message (signal): QDBusMessage(type=Signal, service="org.freedesktop.DBus", path="/org/freedesktop/DBus", interface="org.freedesktop.DBus", member="NameAcquired", signature="s", contents=(":1.1464") )
QDBusConnectionPrivate(0x747021d0) delivery is suspended
QDBusConnectionPrivate(0x747021d0) Adding rule: "type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',arg0='com.actia.platform.io'"
QDBusConnectionPrivate(0x747021d0) sending message: QDBusMessage(type=MethodCall, service="org.freedesktop.DBus", path="/org/freedesktop/DBus", interface="org.freedesktop.DBus", member="GetNameOwner", signature="", contents=("com.actia.platform.io") )
QDBusConnectionPrivate(0x747021d0) got message reply: QDBusMessage(type=MethodReturn, service="org.freedesktop.DBus", signature="s", contents=(":1.2") )
### application.debug: Connecting the PropertiesChanged signal for the created pin...
QDBusConnectionPrivate(0x74710460) : connected successfully
QDBusConnectionPrivate(0x74710460) got message (signal): QDBusMessage(type=Signal, service="org.freedesktop.DBus", path="/org/freedesktop/DBus", interface="org.freedesktop.DBus", member="NameAcquired", signature="s", contents=(":1.28") )
QDBusConnectionPrivate(0x74710460) delivery is suspended
QDBusConnectionPrivate(0x74710460) Adding rule: "type='signal',sender='com.actia.platform.io',path='/com/actia/platform/io/dout1',interface='org.freedesktop.DBus.Properties',member='PropertiesChanged'"
QDBusConnectionPrivate(0x74710460) sending message: QDBusMessage(type=MethodCall, service="org.freedesktop.DBus", path="/org/freedesktop/DBus", interface="org.freedesktop.DBus", member="GetNameOwner", signature="", contents=("com.actia.platform.io") )
QDBusConnectionPrivate(0x74710460) got message reply: QDBusMessage(type=Error, service="org.freedesktop.DBus", error name="org.freedesktop.DBus.Error.NameHasNoOwner", error message="Could not get owner of name 'com.actia.platform.io': no such name", signature="s", contents=("Could not get owner of name 'com.actia.platform.io': no such name") )
QDBusConnectionPrivate(0x74710460) Watching service "com.actia.platform.io" for owner changes (current owner: "" )
### application.debug: PropertiesChanged signal connected successfully to slot
### application.debug: creating a digital in pin...
// comment on the logs: The following 2 lines of debug output originate of instanciating the matching dbus proxy that has been generated by qdbusxml2cpp
QDBusConnectionPrivate(0x747021d0) sending message: QDBusMessage(type=MethodCall, service="org.freedesktop.DBus", path="/org/freedesktop/DBus", interface="org.freedesktop.DBus", member="GetNameOwner", signature="", contents=("com.actia.platform.io") )
QDBusConnectionPrivate(0x747021d0) got message reply: QDBusMessage(type=MethodReturn, service="org.freedesktop.DBus", signature="s", contents=(":1.2") )
### application.debug: Connecting the PropertiesChanged signal for the created pin...
QDBusConnectionPrivate(0x74710460) Adding rule: "type='signal',sender='com.actia.platform.io',path='/com/actia/platform/io/freq_in1_std',interface='org.freedesktop.DBus.Properties',member='PropertiesChanged'"
### application.debug: PropertiesChanged signal connected successfully to slot
### application.debug: success setting pin modes for the digital out pin to pwm generation: true
// comment on the logs: setting a value on an output pin now
QDBusConnectionPrivate(0x747021d0) sending message: QDBusMessage(type=MethodCall, service="com.actia.platform.io", path="/com/actia/platform/io/dout1", interface="com.actia.platform.io.digital_output", member="SetValue", signature="", contents=(200, 80) )
QDBusConnectionPrivate(0x747021d0) got message reply: QDBusMessage(type=MethodReturn, service=":1.2", signature="", contents=() )
### application.debug: success setting pwm of 20 Hz at 80% duty cycle: true
// comment on the logs: reading back the properties for the pins to verify
QDBusConnectionPrivate(0x747021d0) sending message: QDBusMessage(type=MethodCall, service="com.actia.platform.io", path="/com/actia/platform/io/dout1", interface="org.freedesktop.DBus.Properties", member="Get", signature="", contents=("com.actia.platform.io.digital_output", "OutputFrequency") )
QDBusConnectionPrivate(0x747021d0) got message reply: QDBusMessage(type=MethodReturn, service=":1.2", signature="v", contents=([Variant(int): 200]) )
QDBusConnectionPrivate(0x747021d0) sending message: QDBusMessage(type=MethodCall, service="com.actia.platform.io", path="/com/actia/platform/io/dout1", interface="org.freedesktop.DBus.Properties", member="Get", signature="", contents=("com.actia.platform.io.digital_output", "OutputRatio") )
QDBusConnectionPrivate(0x747021d0) got message reply: QDBusMessage(type=MethodReturn, service=":1.2", signature="v", contents=([Variant(int): 80]) )
### application.debug: pwm backread frequency 20, duty cycle 80
// comment on the logs: setting the mode of a digital input pin to read a frequency instead a logical 0 or 1
QDBusConnectionPrivate(0x747021d0) sending message: QDBusMessage(type=MethodCall, service="com.actia.platform.io", path="/com/actia/platform/io/freq_in1_std", interface="com.actia.platform.io.digital_input", member="SetInputType", signature="", contents=(2) )
QDBusConnectionPrivate(0x747021d0) got message reply: QDBusMessage(type=MethodReturn, service=":1.2", signature="", contents=() )
### application.debug: setting pin modes of the digital in pin to read a frequency: true
// comment on the logs: reading the currently applied frequency from the pin now
QDBusConnectionPrivate(0x747021d0) sending message: QDBusMessage(type=MethodCall, service="com.actia.platform.io", path="/com/actia/platform/io/freq_in1_std", interface="org.freedesktop.DBus.Properties", member="Get", signature="", contents=("com.actia.platform.io.digital_input", "InputValue") )
QDBusConnectionPrivate(0x747021d0) got message reply: QDBusMessage(type=MethodReturn, service=":1.2", signature="v", contents=([Variant(int): 17361]) )
### application.debug: reading the current frequency from digital input: 1736.1 Hz
### application.debug: end of actual code during initialization, now issuing QCoreApplication::exec()...
QDBusConnectionPrivate(0x747021d0) dequeueing message QDBusMessage(type=Signal, service="org.freedesktop.DBus", path="/org/freedesktop/DBus", interface="org.freedesktop.DBus", member="NameAcquired", signature="s", contents=(":1.1464") )
QDBusConnectionPrivate(0x74710460) dequeueing message QDBusMessage(type=Signal, service="org.freedesktop.DBus", path="/org/freedesktop/DBus", interface="org.freedesktop.DBus", member="NameAcquired", signature="s", contents=(":1.28") )
[...] program running, waiting for signals
### application.debug: QCoreApplication::quit()
QDBusConnectionPrivate(0x74710460) Removing rule: "type='signal',sender='com.actia.platform.io',path='/com/actia/platform/io/freq_in1_std',interface='org.freedesktop.DBus.Properties',member='PropertiesChanged'"
QDBusConnectionPrivate(0x74710460) Removing rule: "type='signal',sender='com.actia.platform.io',path='/com/actia/platform/io/dout1',interface='org.freedesktop.DBus.Properties',member='PropertiesChanged'"
QDBusConnectionPrivate(0x747021d0) Disconnected
QDBusConnectionPrivate(0x74710460) Disconnected
I read a huge amount of advice that I found on SO or the QT forums about connecting to the PropertiesChanged signal and tried some suggestions from there but to no avail. There must be some signature mismatch which I am not aware of. However I peeked in the code of some dbus applications like networkmanager-qt
and they are using the three arguments that I also use in my signature: QString
,QVariantMap
,QStringList
.
I'm stuck now and hope that anyone has another hint that I could follow. Thanks in advance.
Well, I really do not know why. But when I tried the exact code above again with a fresh from-source qt build (of the same version as before), it worked. So I consider this solved for now.