views:

1383

answers:

1

I'm thinking about serializing data in an application which is Qt-based.

Essentially what I'm going to serialize is my hierarchical model, which is composed of different classes that derive from, say, TreeModelItem:

class TreeModelItem
{
protected:
    QList<TreeModelItem *> m_children;
//...
};

Should I study boost::serialization and go on with it?

Is there any hidden wall I can hit by the way? E.g. while (de)serializing child elements, or when restoring custom singal-slot connections? I hope for the advice of experts.

+3  A: 

QDataStream supports (de)serialization of some popular Qt objects. You can check which ones here. The "Qt" way would be to use that.

However, there's nothing preventing you from using boost, but you will have to implement the serialization for basic objects such as QList all over again, which can be tiresome.

Note that if you have custom objects, such as your TreeModelItem, you would have to provide an operator<< of your own.

Regarding the serialization of signals/slots: afaik Qt doesn't support this atm, and I believe the Qt team has made it this way intentionally. If you're interested why, maybe this read can be helpful.

Idan K
boost handles transparent deserialization of derived classes. How can it be done with Qt?
goodrone
what do you mean by transparent? you must create a (de)serialize function for derived classes aswell which in turn call their parent (de)serialize (indirectly). see here: http://www.boost.org/doc/libs/1_38_0/libs/serialization/doc/tutorial.html#derivedclassesthe same applies to Qt, it just looks different.
Idan K
How to add serialization support for QString can be read here: http://flo.mueckeimnetz.de/2010/01/boostserialization-und-qstring/
fmuecke