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

振华张 zhenhua2000 at gmail.com
Fri Sep 3 11:59:47 CEST 2010


Hi Jeroen,

2010/9/3 Jeroen De Wachter <Jeroen.DeWachter at elis.ugent.be>:
> I overhauled your code to make it work...
> I've had to change quite a bit though, so you might not recognize it :-s

Thanks very much for your help! It's really helpful to resolve the
problem in such a short time.

> I also wanted a C++ program to test it with, so I wrote my own rather
> than rely on your client.py script (I'm just not familiar with Python)
> My client program was written using the same methods as in the tutorial
> I mentioned earlier, btw (and thus uses a generated Interface class)
>
> Some of the stuff I had to do:
>
> your widget class did not have the Q_OBJECT macro, which means the slot
> it provides could never have been called. I added that and put the class
> in a separate source file (because it just makes sense)

Sorry, I forgot it when I copy code from my original project to this
smaller version. I do know we need Q_OBJECT to make signal/slot work.
;-)

> I needed the data type in both the adaptor and the interface
> application, so I split your data definitions to a seperate file as well
> (mydata.h), which is used in both programs

Looks good.

> mydata.cpp contains the streaming operators Qt needs to
> serialize/deserialize the MyData type
> mydata.cpp is also used in both programs, of course...

Another good point I want to thank you. Yes. I should have that part.

> I replaced the QArrayOfData struct with a typedef, so the default
> streaming operators handle the QList<MyData> (you will see that there
> are no extra streaming operators for QArrayOfData)

QArrayOfData actually is a bad idea. Looks like we could simply use:

struct MyData { ...};
Q_DECLARE_METATYPE(MyData)
Q_DECLARE_METATYPE(QList<MyData>)

> I added some dbus type registration calls in both the adaptor program
> and the interface program
>
> I hope this helps... and I recommend you go through that tutorial
> meticulously to learn how Qt handles DBus and custom types

Thank you for your suggestion. I am hurrying up some quick prototype
so apologize for ugly code.

Regards,
Zhenhua

> Kind regards,
>
> Jeroen
>
> On Thu, 2010-09-02 at 18:36 +0200, Thiago Macieira wrote:
>> Em Quinta-feira 02 Setembro 2010, às 16:41:48, Jeroen De Wachter escreveu:
>> > 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
>> [snip]
>>
>> Jeroen is right. There's no call to qDBusRegisterMetaType anywhere in your
>> code and that's required for the type ArrayOfData to be supported.
>>
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
> _______________________________________________
> 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