Results 1 to 2 of 2

Thread: Serializing a Qobject

  1. #1
    Join Date
    Jun 2012
    Posts
    12
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Serializing a Qobject

    Hi,
    i want to serialize my costumes classes ,
    but QDataStream doesn't have any method for that
    and it's operation "<<" doesn't have any QObject or anything else.
    how can i do this?
    please help me!!

  2. #2
    Join Date
    Dec 2011
    Posts
    27
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Serializing a Qobject

    You must create your own streaming operators for the class - otherwise there's no ability for another body of code to automatically determine how to construct/de-construct your class.
    E.g.:

    Qt Code:
    1. Q_DECLARE_METATYPE(MyClass)
    2.  
    3. inline QDataStream& operator<<(QdataStream& out, const MyClass& in) {
    4.  
    5. out << quint32(in.foo());
    6. out << quint32(in.bar());
    7.  
    8. return out;
    9. }
    10.  
    11. inline QDataStream& operator>>(QdataStream& in, const MyClass& out) {
    12.  
    13. quint32 foo;
    14. quint32 bar;
    15. in >> foo;
    16. in >> bar;
    17.  
    18. out.setFoo(foo);
    19. out.setBar(bar);
    20.  
    21. return in;
    22. }
    To copy to clipboard, switch view to plain text mode 

    See also: http://stackoverflow.com/questions/2...zation-with-qt

Similar Threads

  1. Serializing QHash to a QByteArray
    By PeterThePuter in forum Qt Programming
    Replies: 3
    Last Post: 17th December 2010, 23:19
  2. Serializing QImage
    By lukass in forum Newbie
    Replies: 1
    Last Post: 26th October 2010, 18:58
  3. Serializing
    By xyzt in forum Qt Programming
    Replies: 1
    Last Post: 23rd March 2008, 08:51
  4. Replies: 1
    Last Post: 31st October 2007, 14:14
  5. help on QObject::tr()
    By sincnarf in forum Qt Programming
    Replies: 1
    Last Post: 16th October 2007, 07:52

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.