[Qt-interest] qdbusxml2cpp custom signatures, howto?

Thiago Macieira thiago.macieira at trolltech.com
Thu Feb 5 13:46:44 CET 2009


Em Quinta-feira 05 Fevereiro 2009, às 13:13:51, Juan Navarro escreveu:
> *) 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)

Good. But you also need to Q_DECLARE_METATYPE(QList<PropertyUpdate>).

> *) Implemented the marshalling methods as indicated by the QDBusArgument
> docs, in HalDevice.cpp:
[snip]

Correct.

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

Register the QList one as well. That's the type you're actually receiving.

> *) 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?)

Yes.

> *) 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

Please note that using class names starting with Q and another capital letter 
is not a good idea, since we basically reserve all of them for us internally. 
A future version of Qt could conflict with your class. 

But that's not the core of the issue here.

> 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).

The missing registration is the problem. You've told QtDBus how to handle 
PropertyUpdate structures, but not what "QList<PropertyUpdate>" is.

> 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?

Yes, that would do it. Registering both is just a good idea.

-- 
Thiago Macieira - thiago.macieira (AT) nokia.com
  Senior Product Manager - Nokia, Qt Software
     Sandakerveien 116, NO-0402 Oslo, Norway
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090205/d001071c/attachment.bin 


More information about the Qt-interest-old mailing list