QtDBus and user types problem

Thiago Macieira thiago at kde.org
Sat Nov 4 02:27:52 PST 2006

Sebastian Trüg wrote:
>Now when I use  QDBusInterface::callWithArgumentList to retrieve a
> return value of type MyUserType I get a QList<QVariant>. And the
> QVariant contains a QDBusArgument instead of MyUserType.
>Is this intended behaviour? 

Yes, it's the intended behaviour. It's the "lazy demarshaller" I invented 
(dubbed Pattern Buffer). What it does is that it decodes only what it 
unambiguously knows about: integers, floating point, strings (includes 
object path and signature), as well as array of string and array of 

Anything else gets shoved into a "QDBusArgument" for later decoding.

The technical reason for that is that a signature of, for instance, "(ii)" 
could be produced by more than one user type (e.g., QPoint and QSize). 
The marshaller can't know what to do in those cases.

>Isn't is possible to demarshall it already and provide a MyUserType in
>the QVariant? 

No, for the reasons above.

>And if not, is there a generic way for me to demarshall it manually into
> the registered user types so I can provide a clean QVariant-based
> interface in my Message class?

qdbus_cast<> does that for you. For example:

QVariantList::Iterator it = reply.begin();
for ( ; it != reply.end(); ++it)
    if (it->userType() == qMetaTypeId<QDBusArgument>())
        *it = qdbus_cast<MyUserType>(*it);

This will translate all QDBusArguments to MyUserType. If the conversion 
fails, the QVariant will be null, so you can try multiple conversions to 
see which one works.

You can also do:
    QDBusArgument arg = qvariant_cast<QDBusArgument>(*it);
and then analyse currentSignature() if you have more than one type.
  Thiago Macieira  -  thiago (AT) macieira.info - thiago (AT) kde.org
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/dbus/attachments/20061104/8a6606ed/attachment.pgp

More information about the dbus mailing list