[Qt-interest] qdbusxml2cpp custom signatures, howto?

Juan Navarro juan.nm at vaelsys.com
Thu Feb 5 13:13:51 CET 2009


Hello all :)
I would like to ask you for help with the implementation in Qt of the HAL D-Bus 
interface. My main problem is with the interface "org.freedesktop.Hal.Device": 
it emits a signal called "PropertyModified", and its arguments are "Int 
num_changes, Array of struct {String property_name, Bool added, Bool removed}".

So, when introspecting this interface and generating a XML file describing it, 
by issuing the following command:

$ qdbus --system org.freedesktop.Hal <some Device object> \
org.freedesktop.DBus.Introspectable.Introspect > Hal.Device.xml

inside the file we find the following signal description with an unsupported 
type signature: "a(sbb)"

<signal name="PropertyModified">
	<arg name="num_updates" type="i"/>
	<arg name="updates" type="a(sbb)"/>
</signal>

So because of the lack of clear documentation about how to manage this signal, I 
need a bit of help :)

I describe what I have done by now:

*) Created a custom struct in my HalDevice.h file (that is my C++ "mirroring" 
class for the org.freedesktop.Hal.Device interface):
struct PropertyUpdate
{
	QString propertyName;
	bool isAdded;
	bool isRemoved;
};
Q_DECLARE_METATYPE(PropertyUpdate)


*) Implemented the marshalling methods as indicated by the QDBusArgument docs, 
in HalDevice.cpp:
// Marshall the PropertyUpdate data into a D-BUS argument.
QDBusArgument& operator<<(QDBusArgument& argument, const PropertyUpdate& mystruct)
{
	argument.beginStructure();
	argument << mystruct.propertyName << mystruct.isAdded << mystruct.isRemoved;
	argument.endStructure();
	return argument;
}

// Retrieve the PropertyUpdate data from the D-BUS argument.
const QDBusArgument& operator>>(const QDBusArgument& argument, PropertyUpdate& 
mystruct)
{
	argument.beginStructure();
	argument >> mystruct.propertyName >> mystruct.isAdded >> mystruct.isRemoved;
	argument.endStructure();
	return argument;
}


*) Registered the PropertyUpdate type in the HalDevice constructor:
qDBusRegisterMetaType<PropertyUpdate>();


*) Added an "annotation" element to the XML interface description:
<signal name="PropertyModified">
	<arg name="num_updates" type="i"/>
	<arg name="updates" type="a(sbb)"/>
	<annotation name="com.trolltech.QtDBus.QtTypeName.In1"
value="QList&lt;PropertyUpdate&gt;"/>
</signal>

(¿Is this the correct way of declaring a list of PropertyUpdate structs?)


*) At last, I generate a QHalDeviceInterface class by issuing the following command:
$ qdbusxml2cpp -i HALDevice.h -c QHalDeviceInterface -N \
-p QHalDeviceInterface Hal.Device.xml org.freedesktop.Hal.Device

And then connect the generated signal:
QHalDeviceInterface::PropertyModified(int num_updates, const 
QList<PropertyUpdate> &updates)
to my slot:
HalDevice::propertyModifiedSLT(int numUpdates, const QList<PropertyUpdate>& updates)

Well, at this point, my problem is as simple as the slot not being called, even 
when the signal IS efectively being emmited (I know that because I'm inspecting 
all emitted signals with the "dbus-monitor" command).

Any help or comments about the implementation would be thanked a lot :)

Maybe instead of registering a struct and then using a QList of that struct, 
should I register directly a QList<myStruct> as the custom type?



More information about the Qt-interest-old mailing list