PDA

View Full Version : Retriving structure in qt-urgent.please reply.



savaliya_ambani
20th July 2010, 10:52
i am sending a strucutre though dbsu-glib as follow.
typedef struct{
int a;
int b;
char [5];
}payload;

payload p={5,5,"ARRAY"};

And i am able to send this structure data with function call,which i can see in dbus-monitor as follow.
array[
array[
byte 5;
byte 5;
byte 65;
....
byte 89;
]
]
signature is :'aay'
up to this every thing is OK.

But on qt side(receiver) i dont have any idea as to how to receive this message.what can be the argument of my function in qt application?

i tried with QByteArray,QStringList but no succusses.now,what to do?

These are my confusion:
(1)how to imeplement a method in qt ,which can suites to 'aay' signatures displayed in dbus-monitor?
(2) if we use QDBusArgument for receving structure and arrays,than how should be an implementatin.If remote application is sending the structure,than how to retrieve it at qt ?
(3)what are the ways of receiving structures in qt?

dear freind,no body is replying since long.is it so no one knows about this??

wysota
20th July 2010, 12:03
Most likely the arguments are (int, int, QByteArray). I suggest you use qdbusviewer to find your method and see what the argument types are. Furthermore there is an example in QDBusArgument docs that shows how to deal with structures.


dear freind,no body is replying since long.is it so no one knows about this??
We don't like it when someone uses the word "urgent" in the thread title. It tends to cause significant delays receiving answers to questions. Ignoring proper formatting and language in your posts also doesn't help with getting replied.

savaliya_ambani
20th July 2010, 12:24
Dear Wysota,

Thank you very much for replying. I am really sorry for my mistakes. Please, forgive me about my unformated post because of poor english.

I have tried with qdbusviewer also many times. But it will only accept this arguments only.

In my case, i am only getting the refrence to a structure(i dont know what is inside it,so i have to try to send it as a string of bytes or array of bytes),i am making GPtrArray (used for adding any mixed type of data) and sending by dbus_g_proxy_begin_call to a remote function.

but,when i send this its showing 'aay' signature. now,if one member element gets added or removed of any data type by the 3 rd application(which is giving me a structure).Than what to do. Probably the best way is to send as byte stream with message identifier. And interpret it as receiver side as per the message id received.

But,still i am not able to receive with the (int, int, QByteArray). i have used QDBusArgument ,but than confusion is that,what can be argument of method ?is it foo(mystructure)?

wysota
20th July 2010, 14:28
Did you find your method using qdbusviewer? Can you attach a screenshot of a window that opens after doubleclicking the method name in qdbusviewer?

savaliya_ambani
21st July 2010, 05:02
yah,i have already seen all the methods of my class.And i if i give it foo(int,int,QString),than i can call with the qdbusviewer,but with the arguments as (int,int,QString) only.

And when i call from remote glib-dbus application with the arguments as "array of array of integers" i.e. 'aay' which is shown by the dbus-monitor after passing with the GPtrArray . It shows the message "no member named "foo" with signature 'aay' ". I can call all other method which takes "array of strings","int" and all basic data types. But 'aay' is not working.

now what should i do?. If any how i can make a string from the structure given to me,than i will have to send as string and i will be able to receive as QString .

can i have another solution?

wysota
21st July 2010, 09:32
yah,i have already seen all the methods of my class.And i if i give it foo(int,int,QString),than i can call with the qdbusviewer,but with the arguments as (int,int,QString) only.
So that's what you need to use.


now what should i do?. If any how i can make a string from the structure given to me,than i will have to send as string and i will be able to receive as QString .

can i have another solution?
The method declaration claims the last argument is a 5 byte character array - meaning a string. I'm not sure how a two dimensional array of integers would fit there. If you can, you should redesign the original method, it's declared incorrectly.

savaliya_ambani
21st July 2010, 11:25
i cant do this with (int,int,Qstring),because i dont know the elements of structure.I will get only refrence to a structure. This is not possible in the case i am fighting. i must have to send it as one string.

i have found a way for sending a structure as a string by memcpy() and than sending the memory data upto the sizeof(structure) .But the problem with this is that it will get terminated if any structure variable is 0(zero).

Any idea more on this,as to how to handle this?

wysota
21st July 2010, 12:37
Redesign the structure. QString holds unicode strings and if you try to fit arbitrary data in it, it might get corrupted during the conversion to Unicode.

savaliya_ambani
22nd July 2010, 05:03
i didnt get this. How can i redesign,the data memebers will be there still. can u please give me example of structure ,which consists of int,string,int,chat,boolean.

When a single null terminated string found,it will terminate it there.

wysota
22nd July 2010, 09:22
i didnt get this. How can i redesign,the data memebers will be there still.
Change the program that declares the DBus method to not use char[5].

alainstgt
22nd July 2010, 10:25
As a Windows programmer, I am not in DBUS, but what you have to do is mentioned in the part "The QtDBus Type System | Extending the type system" and "QDBusArgument Class Reference" of the documentation:
1. declare your structure as a Qt meta-type (Q_DECLARE_METATYPE)
2. reimplement the streaming operators << and >>
3. in your programm, you should register (qDBusRegisterMetaType()) your datatype

Concerning the char array issue, you could use a QString or send the chars one by one, surely not elegant but it could work...

wysota
22nd July 2010, 10:31
Concerning the char array issue, you could use a QString or send the chars one by one, surely not elegant but it could work...
As I understand it the point is those chars are not actually chars but pointers to pointers to integers (or something like that, it's hard to understand the OP). Otherwise I don't see what the problem is, as I said the docs for QDBusArgument contain a nice example of dealing with structures.

savaliya_ambani
22nd July 2010, 12:42
As i said its not in my hand to change the structure. I will get only refrence to it,and need to convert it into a string.



In another method i am passing a structure from nonqt application. And its signature shown is '(suu)',means structure consisting of "string,unsiged int,unsigned int." . But,i cant register a method from qt which can accept a method call like this.Even with qdbusviewer cant do this.

And if i do

1. declare your structure as a Qt meta-type (Q_DECLARE_METATYPE)
2. reimplement the streaming operators << and >>
3. in your programm, you should register (qDBusRegisterMetaType()) your datatype

than there will not be a method which can have the foo(string,unsiged int,unsigned int.) method.