Results 1 to 12 of 12

Thread: XML Serialization of Qt Objects ??

  1. #1
    Join Date
    Jul 2012
    Posts
    40
    Qt products
    Qt4 Qt/Embedded

    Default XML Serialization of Qt Objects ??

    Hi all,
    How can we do XML serialization for the Qt objects?????

    class Student
    {
    public :
    int sno=10;
    Qstring name="Sai"
    Qstring phno="989898111"
    }

    class second
    {
    Student stu_obj=new Student();
    qdebug()<<stu_obj.sno<<stu_obj.name<<<stu_obj.phno ; // Whcih prints all those details
    }

    Now how can i do XML serialize for this stu_obj in qt ,so that we can transfer for service api over web?????

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: XML Serialization of Qt Objects ??

    Any way you like: manually write strings, use QXmlStreamWriter, or DomDocument.

  3. #3
    Join Date
    Jul 2012
    Posts
    40
    Qt products
    Qt4 Qt/Embedded

    Default Re: XML Serialization of Qt Objects ??

    Thanks for reply....No its not possible because the Service API which i need to hit/access accepts only xml/json serialized object ....is this Posisble in Qt or not plz give me some idea on dis ???? like we have in .net(http://support.microsoft.com/kb/815813) or Java.......??

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 284 Times in 279 Posts

    Default Re: XML Serialization of Qt Objects ??

    Mr Google is Yours friend. Look at this and this.

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

    Default Re: XML Serialization of Qt Objects ??

    Quote Originally Posted by sai_3289 View Post
    No its not possible because the Service API which i need to hit/access accepts only xml/json serialized object
    If it accepts XML serialied objects than of course this is possible by the option suggested by ChrisW67. All of those options, especially QXmlStreamWriter and QDomDocument, produce XML.

    You can easily try those approaches stand-alone, e.g. creating an XML document and writing it to a file instead of sending it to a server.

    Cheers,
    _

  6. #6
    Join Date
    Jul 2012
    Posts
    40
    Qt products
    Qt4 Qt/Embedded

    Default Re: XML Serialization of Qt Objects ??

    Thanks for reply.....
    creating an XML document and writing it to a file or parsing an xml file has been done successfully by using 2 ways i.e QxmlStreamWriter/Reader and QDomDocument.
    Like we have in .net(http://support.microsoft.com/kb/815813) ,IS DIS POSSIBLE IN QT OF SERIALIZING an OBJECT to XML or NOT ????
    Here my requirement is to synch to server at any given time,using provided web service api.

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

    Default Re: XML Serialization of Qt Objects ??

    This is not directly possible in Qt (I mean Qt does not have such API).

    Yes is defenetly possible in Qt you need to write the XML by youself using the classes you already found.
    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.

  8. #8
    Join Date
    Jul 2012
    Posts
    40
    Qt products
    Qt4 Qt/Embedded

    Default Re: XML Serialization of Qt Objects ??

    Thank a lot for d reply.....
    Ok after writing required xml..how do we can post that to web service API.....Where My service API accepts only xml type objects...

  9. #9
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 284 Times in 279 Posts

    Default Re: XML Serialization of Qt Objects ??

    sai_3289, do You check out the links on the post No. 4 ?

  10. #10
    Join Date
    Jul 2012
    Posts
    40
    Qt products
    Qt4 Qt/Embedded

    Default Re: XML Serialization of Qt Objects ??

    Thank a lot for d response........Yeah lesiok....in that post no 4 accessing the webservice is done by using query string means binding the values to url directly....
    But if we need to pass around 15 values or more it's not possible because we get an error as querystring lenght exceeds.
    so we need to make use of object serialization concept here and which i need it.. ....or is der any other way to solve???

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

    Default Re: XML Serialization of Qt Objects ??

    But if we need to pass around 15 values or more it's not possible because we get an error as querystring lenght exceeds
    Where did you get the error from?

    Dear sai_3289, the link you referred in earlier post is related to converting the state of object (C# object to be precise) in to a serial stream so that it can be saved/transmitted in to a database/server/file/memory/console/where ever you want it to go. One important point here is that serialization format is specific to C# object types. Note the the link says "Serialization is the process of taking the state of an object and persisting it in some fashion". The last couple of words are important

    Now, if I understood your post/question correctly, you are tying to convert a C++ (may be a QT C++ objcet) into a serial stream. Well you can do it but don't expect it work with your C#.Net application.

    Here is just an example

    Qt Code:
    1. class clsPerson
    2. {
    3. public:
    4. QString FirstName;
    5. QString MI;
    6. QString LastName;
    7. };
    8.  
    9. clsPerson p;
    10. p.FirstName = "Jeff";
    11. p.MI = "A";
    12. p.LastName = "Price";
    13.  
    14. QString serial;
    15. QXmlStreamWriter stream(&serial);
    16. stream.setAutoFormatting(true);
    17. stream.writeStartDocument();
    18.  
    19. stream.writeStartElement("clsPerson");
    20. stream.writeAttribute("xmlns:xsi", "?");
    21. stream.writeAttribute("xmlns:xsd", "?");
    22.  
    23. stream.writeTextElement("FirstName",p.FirstName);
    24. stream.writeTextElement("MI",p.MI);
    25. stream.writeTextElement("LastName",p.LastName);
    26.  
    27. stream.writeEndElement();
    28.  
    29. stream.writeEndDocument();
    30.  
    31. qDebug() << serial.toStdString().c_str();
    To copy to clipboard, switch view to plain text mode 
    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.

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

    Default Re: XML Serialization of Qt Objects ??

    Quote Originally Posted by sai_3289 View Post
    But if we need to pass around 15 values or more it's not possible because we get an error as querystring lenght exceeds.
    That sounds like all data is being encoded into the URL.
    Did you used a GET or POST operation?

    Quote Originally Posted by sai_3289 View Post
    so we need to make use of object serialization concept here and which i need it.. ....or is der any other way to solve???
    Given that you have the serialization covered already, the problem now lies with sending the serialized data. The Web service's API documentation should have some information about the expected operation (usually HTTP POST) and about meta data (such as required HTTP headers) that needs to be present.

    Cheers,
    _

Similar Threads

  1. Xml Serialization ???
    By sai_3289 in forum Qt Programming
    Replies: 7
    Last Post: 28th December 2012, 10:59
  2. Replies: 3
    Last Post: 9th January 2010, 15:47
  3. XML Serialization of Qt Objects
    By sasi in forum Qt Programming
    Replies: 1
    Last Post: 29th June 2009, 19:25
  4. Serialization
    By donmorr in forum Qt Programming
    Replies: 4
    Last Post: 16th November 2006, 13:51
  5. Replies: 7
    Last Post: 18th July 2006, 21:33

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.