PDA

View Full Version : How could I serialize my classes?



ricardo
26th June 2009, 12:38
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.

aamer4yu
26th June 2009, 13:21
May be QDataStream might be of some help to you

ricardo
26th June 2009, 13:53
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.

shentian
26th June 2009, 19:21
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.

nanortemis
28th June 2009, 09:13
Check also this

http://code.google.com/p/qboard/wiki/S11nQt

wysota
28th June 2009, 10:30
Check also this

http://code.google.com/p/qboard/wiki/S11nQt

What does it have that QDataStream doesn't do? I really can't see the difference.

skydave
28th June 2009, 14:09
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.

wysota
28th June 2009, 15:57
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.

ricardo
28th June 2009, 18:32
What about serializing without a QT enviroment?

BTW, thanks for replies.

wysota
28th June 2009, 19:09
What about serializing without a QT enviroment?

It's hard to use Qt if you don't have it available...

ricardo
28th June 2009, 19:45
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)?

wysota
28th June 2009, 20:40
You can use the suggested s11n library.

RThaden
29th June 2009, 17:05
Have a look at the boost serialization library (http://www.boost.org/doc/libs/1_39_0/libs/serialization/doc/index.html)

Regards,

Rainer