[Qt-interest] Fwd: A Qt-dbus question

Jeroen De Wachter Jeroen.DeWachter at elis.ugent.be
Thu Sep 2 16:41:48 CEST 2010


Hi,

I think you lack some streaming operators in your code...
Qt has no built-in way to find out how to serialize your custom MyData
struct.

You should take a look at the documentation at
http://doc.trolltech.com/4.6/qdbusargument.html#details
to see how to do add those operators

I'd also suggest using a typedef for your ArrayOfData instead of the
struct. Otherwise, you will need to add streaming operators for the
ArrayOfData struct as well, while Qt should be perfectly able to handle
the QList<MyData> directly.
Mind, you will still need the typedef as you can't use the
'QList<MyData>' type directly in the XML due to the < and > characters

You could also take a look at this tutorial I wrote a little while ago:
http://techbase.kde.org/Development/Tutorials/D-Bus/CustomTypes
It deals with custom types and DBus. Even if you don't want to use
adaptors/interfaces, there's a lot of info on just custom types there as
well.

Kind regards,

Jeroen

On Thu, 2010-09-02 at 22:10 +0800, 振华张 wrote:
> Hi Thiago,
> 
> 2010/9/2 Thiago Macieira <thiago at kde.org>:
> > On Thursday 2. September 2010 04.43.34 振华张 wrote:
> >> Attached is the compilable version of my problem. To reproduce my
> >> problem, unzip and build the file. You may need copy myobject.conf to
> >> /etc/dbus-1/system.d and restart dbus daemon.
> >>
> >> The key point is the parameter of MyMethod is "a(sy)" type. If I
> >> change the parameter to a simple "s", everything works fine.
> >
> > This example has a(sy) with a type information of QString. That will never
> > work, because a QString is not an array of (QString,byte).
> 
> Oops, you are right. It's a mistake during code modification. So I
> change the xml back to "value=\"QArrayOfData\"", where QArrayOfData is
> a METATYPE declared in myclass.h. However, the problem does still
> exist. Could you help find any problems in my code? The updated
> project is attached. Thanks!
> 
> struct MyData {
>     QString text;
>     uchar icon;
> };
> 
> Q_DECLARE_METATYPE(MyData)
> 
> struct QArrayOfData {
>     QList<MyData> items;
> };
> 
> Q_DECLARE_METATYPE(QArrayOfData)
> 
> Regards,
> Zhenhua
> 
> > --
> > Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
> >  Senior Product Manager - Nokia, Qt Development Frameworks
> >      PGP/GPG: 0x6EF45358; fingerprint:
> >      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
> >
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest





More information about the Qt-interest-old mailing list