Results 1 to 13 of 13

Thread: How could I serialize my classes?

  1. #1
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question How could I serialize my classes?

    I have a class that represents a level (it has monsters, platforms, characters classes associated...), it uses STL containers and QString (which I could remove)

    My question is: How can I save automatically those classes on hard disck? I mean, without writing large Load/Save/Traverse methods, is there any way or library or STL function?

    I believe BOOST have something, but not sure. Does Qt have anything? What do you recommend me?

    Thanks in advance.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How could I serialize my classes?

    May be QDataStream might be of some help to you

  3. The following user says thank you to aamer4yu for this useful post:

    ricardo (26th June 2009)

  4. #3
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How could I serialize my classes?

    Quote Originally Posted by aamer4yu View Post
    May be QDataStream might be of some help to you
    Must I save my class manually? Or is there anything like: something << my_class?

    Thanks.

  5. #4
    Join Date
    May 2009
    Posts
    62
    Thanks
    2
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How could I serialize my classes?

    You can overload the operators << and >> for your classes. They are already provided for native types and many Qt types such as QString, QPoint, QList.

  6. #5
    Join Date
    Feb 2009
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How could I serialize my classes?


  7. #6
    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: How could I serialize my classes?

    Quote Originally Posted by nanortemis View Post
    What does it have that QDataStream doesn't do? I really can't see the difference.
    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.


  8. The following user says thank you to wysota for this useful post:

    ricardo (28th June 2009)

  9. #7

    Default Re: How could I serialize my classes?

    Quote Originally Posted by wysota View Post
    What does it have that QDataStream doesn't do? I really can't see the difference.
    There is none I guess.

    I wonder how they would serialize signal/slots (they write its easy) because I tried it and failed mainly because its not possible to iterate over all receivers attached to a signal.

  10. #8
    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: How could I serialize my classes?

    I'm not sure how a serialized signal would look like

    By the way, the explanation about QDataStream on S11nQt website is really lame. s11n is as proprietary as QDataStream And (de)serializing Qt objects in a non-Qt environment wouldn't make sense so you are limited to the Qt environment anyway and QDataStream is available there.
    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.


  11. The following user says thank you to wysota for this useful post:

    ricardo (28th June 2009)

  12. #9
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How could I serialize my classes?

    What about serializing without a QT enviroment?

    BTW, thanks for replies.

  13. #10
    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: How could I serialize my classes?

    Quote Originally Posted by ricardo View Post
    What about serializing without a QT enviroment?
    It's hard to use Qt if you don't have it available...
    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. The following user says thank you to wysota for this useful post:

    ricardo (28th June 2009)

  15. #11
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How could I serialize my classes?

    Quote Originally Posted by wysota View Post
    It's hard to use Qt if you don't have it available...
    I mean, which library should I use to serialize in a common C++ program (w/o Qt)?

  16. #12
    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: How could I serialize my classes?

    You can use the suggested s11n library.
    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. The following user says thank you to wysota for this useful post:

    ricardo (28th June 2009)

  18. #13
    Join Date
    Jan 2008
    Posts
    56
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How could I serialize my classes?

    Have a look at the boost serialization library

    Regards,

    Rainer

  19. The following user says thank you to RThaden for this useful post:

    ricardo (29th June 2009)

Similar Threads

  1. Serialize a C++ string in QDatastream
    By Denarius in forum Qt Programming
    Replies: 2
    Last Post: 1st April 2009, 13:40
  2. Replies: 2
    Last Post: 13th March 2009, 11:23
  3. private classes in QT
    By talk2amulya in forum Qt Programming
    Replies: 3
    Last Post: 19th February 2009, 17:26
  4. Professional Classes & Objects Structure
    By webstylemedia in forum Newbie
    Replies: 4
    Last Post: 4th August 2008, 10:50
  5. Adding nonQt classes to QtApplication
    By codebehind in forum Newbie
    Replies: 11
    Last Post: 23rd April 2007, 21:08

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.