QtDBus and user types problem
Sebastian Trüg
strueg at mandriva.com
Sat Nov 4 02:09:00 PST 2006
I see.
thanks a lot for the help.
So there is no generic way to it. Ok. One last question although I think the
answer is no: Would it be possible to get the raw data from the QDBusArgument
to have it demarshalled elsewhere?
Cheers,
Sebastian
On Saturday 04 November 2006 11:27, Thiago Macieira wrote:
> 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
> bytes.
>
> 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.
More information about the dbus
mailing list