Page 1 of 2 12 LastLast
Results 1 to 20 of 31

Thread: Serialization Of Xml using QObjects

  1. #1
    Join Date
    Jul 2012
    Location
    Hyderabad
    Posts
    82
    Thanks
    5
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Red face Serialization Of Xml using QObjects

    Dear Forums,


    I have a doubt regarding using XML serialization to generically serialize any ole QObject. This kinda perplexes me because all the needed elements appear to be within Qt. Qt has XML serialization classes and reflection through its meta data system, yet no XML serialization function that accepts a QObject.Please provide me with a specific solution...........Thanks in Advance......Any solution would be appreciable...............


    Regards,

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Serialization Of Xml using QObjects

    In general XML is used for information exchange, where you would typically serialize somthing (QObject) to send it across to some other party (or software etc). Now the important requirement is that both parties should agree on the XML schema of the serialized QObject. I think it is this lack of a standard of specifying the schema of the QObject is one main reason for not having such serialization API/function.

    Moreover it gets complicated for custom (derived QObjects) where the derivered QObject definition may not be always be inline with Qt Meta System. (I mean properties etc), may be this is another reason.

    Anyway it is possible to come up with a simple mechanism using a combination of one or more of the framework classes QDocDocument, QSetting, QVariant, QXmlStreamWriter, to write a custom XML serialization schema
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Jul 2012
    Location
    Hyderabad
    Posts
    82
    Thanks
    5
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Red face Re: Serialization Of Xml using QObjects

    Dear Santosh,


    Thanks for the reply........Actually i dint understand the way you said ..........Can you give me an example so that it would be very favourable to understand for me..........Any solution would be appreciable.........Thanks in Advance........


    Regards,

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Serialization Of Xml using QObjects

    I meant that Qt already has enough support so that one can write serialization (XML or any other type) them selfs
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  5. #5
    Join Date
    Jul 2012
    Location
    Hyderabad
    Posts
    82
    Thanks
    5
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Red face Re: Serialization Of Xml using QObjects

    Dear Santosh,


    Thanks for the reply..........Can you just me a sample program on how to do it pretty confused in writing it..............Any solution would be appreciable........Thanks in Advance........


    Regards,

  6. #6
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Serialization Of Xml using QObjects

    It depends, what do you want to do with the serialized XML data?
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  7. #7
    Join Date
    Jul 2012
    Location
    Hyderabad
    Posts
    82
    Thanks
    5
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Serialization Of Xml using QObjects

    Dear Santosh,

    Thanks for the reply..........What i need is i have to hit the live database of our .net application so for that i need to serialize my data in the form of an object and then send it to hit the live db of our application...........Hope you got me..........Any solution would be appreciable.Thanks in advance........


    Regards,

  8. #8
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Serialization Of Xml using QObjects

    It is not clear to me.

    Who will read the DB (the Qt Applciation / .Net serialization API)?
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  9. #9
    Join Date
    Jul 2012
    Location
    Hyderabad
    Posts
    82
    Thanks
    5
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Serialization Of Xml using QObjects

    Dear Santosh,

    I will explain in brief i have a device,In that Device database i save my transaction data ..I need to insert this data in server DB....so now i get my required data from Device db to transfer to server through QUERYING. For example i got 5 rows with 10 columns........now to insert this records in SERVER Database,I need to do serialization for these result and hit the web service with that serialized object to pass these data and get inserted in the SERVER Database....????
    ->Passing anything either xml/json serialization object has to been done, to hit web service .Hope you got me now...........Thanks in Advance.........Any Solution would be appreciable........


    Regards,

  10. #10
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Serialization Of Xml using QObjects

    Who do you think will read/get this serilaized data from server, and how will they understand the xml serialization scheme you used to serialize?

    I think i am completly off the page, or missed someting.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  11. #11
    Join Date
    Jul 2012
    Location
    Hyderabad
    Posts
    82
    Thanks
    5
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Serialization Of Xml using QObjects

    Dear Santosh,

    Thanks for the reply.........Actually we have an Service(Api) in the .net now what we are going to do is we serialize(Xml/Json) the data that we get from the Qt as an object say for example the object contains about more than 10 fields and send that to the server after serialization(Xml/Json)......In the Server through this Service it gets hit ....Hope you got me...........Thanks in Advance.......Any Solution would be appreciable....

    Regards,

  12. #12
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Serialization Of Xml using QObjects

    I am not sure of Service(Api), whatever it is, find out the XML scema it requires and useQDomDocument to prepare the XML data. Refer Qt docs for QDomDocument, it shows how to creare XML.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Serialization Of Xml using QObjects

    I think OP's app is going to be the only one reading the data (the DB is probably only for storage) so it doesn't really matter how the serialization is implemented as long as it is reversible. The most trivial (in terms of implementation) solution I can think of is to store the class name and values for all properties of a given object as separate tags in the xml (using QObject meta-data) before proceeding to children of the object. It should be easy to implement using QXmlStreamWriter and QXmlStreamReader.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. #14
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Serialization Of Xml using QObjects

    Lets assume we have a database query and we want to format it in XML as a table. That would be something like this:

    Qt Code:
    1. QString xmlText;
    2. QXmlStreamWriter writer( &xmlText );
    3.  
    4. writer.writeStartDocument( "1.0" );
    5. writer.writeStartElement( "table" );
    6.  
    7. while ( query.next() ) {
    8. QSqlRecord row = query.record();
    9.  
    10. writer.writeStartElement( "row" );
    11.  
    12. for ( int col = 0; col < row.count(); ++col ) {
    13. QSqlField column = row.field( col );
    14.  
    15. writer.writeStartElement( "column" );
    16.  
    17. writer.writeAttribute( "name", field.name() );
    18. writer.writeCharacters( field.value().toString() );
    19.  
    20. writer.writeEndElement(); // column
    21. }
    22.  
    23. writer.writeEndElement(); // row
    24. }
    25.  
    26. writer.writeEndElement(); // table
    27. writer.writeEndDocument();
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  15. #15
    Join Date
    Jul 2012
    Location
    Hyderabad
    Posts
    82
    Thanks
    5
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Red face Re: Serialization Of Xml using QObjects

    Dear anda_skoa,


    Thanks for the reply...........It would be very favourable for all of us if you provide us with a better examples....Because the one you provided is not that clear to me as im pretty new to this concept too,hope the better example that you give will help me as well as others who are looking for it too....Any Solution would be appreciable.....Thanks in Advance......


    Regards,

  16. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Serialization Of Xml using QObjects

    What exactly of what anda_skoa provided is not clear to you? The code is pretty much self explanatory.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  17. #17
    Join Date
    Jul 2012
    Location
    Hyderabad
    Posts
    82
    Thanks
    5
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Serialization Of Xml using QObjects

    Dear wysota,


    Thanks for the comments........Actually im very new to this concept so what he has given the code might be very clear by as im a beginner in this not getting what exactly he has done....If i am little bit familiar with it then i can code the remaining,but my problem is im pretty new and not knowing how to code a sample QDomDocument it would be favourable if you give me an idea with an example.....Thanks in Advance....Any solution would be appreciable......



    Regards,

  18. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Serialization Of Xml using QObjects

    Quote Originally Posted by StarRocks View Post
    Thanks for the comments........Actually im very new to this concept so what he has given the code might be very clear by as im a beginner in this not getting what exactly he has done....If i am little bit familiar with it then i can code the remaining,but my problem is im pretty new and not knowing how to code a sample QDomDocument it would be favourable if you give me an idea with an example.....Thanks in Advance....Any solution would be appreciable......
    Repeating over and over that you are new to a subject or that you're not familiar with it will not get you anywhere. Read the docs and examples that go with it about QDomDocument or QXmlStreamWriter and then come back here and ask specific questions about specific things you don't understand. If you're expecting to get code that you can simply copy and paste into your application that will do exactly what you want, then you will be disappointed -- nobody here will provide you with such code. There is no QSerializeQObjectsIntoXmlTheWayStarRocksNeedsIt class in Qt.
    Last edited by wysota; 3rd January 2013 at 12:13. Reason: spelling corrections
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  19. #19
    Join Date
    Jul 2012
    Location
    Hyderabad
    Posts
    82
    Thanks
    5
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Serialization Of Xml using QObjects

    Dear wysota,


    Thanks for the comments..........I have done a code but i am getting an error message as "error: expected type-specifier before 'frmMain'" ....I guess the frmMain should be as the Class name as Contact but when i give that its not showing me an option "show"...i guess im missing something....please find the attachment of my code for your reference......Any solution would be appreciable......Thanks in Advance......



    Regards
    Attached Files Attached Files

  20. #20
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Serialization Of Xml using QObjects

    You forgot to include the file that defines the "frmMain" class.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 1
    Last Post: 11th August 2011, 14:18
  2. Creating QObjects before QCoreApplication
    By dawwin in forum Qt Programming
    Replies: 2
    Last Post: 13th April 2011, 18:00
  3. Generic XML Serialization of QObjects
    By nickolais in forum Qt Programming
    Replies: 3
    Last Post: 23rd March 2011, 08:47
  4. Find QObjects that insatlled event filter
    By babu198649 in forum Qt Programming
    Replies: 4
    Last Post: 15th December 2010, 11:27
  5. QObjects as data members stored by value
    By Radagast in forum Qt Programming
    Replies: 3
    Last Post: 6th August 2009, 19:14

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.