I have an inheritance tree like :

Qt Code:
  1. BaseClass : QObject {
  2. Q_OBJECT
  3. // etc..
  4. } ;
To copy to clipboard, switch view to plain text mode 
Qt Code:
  1. ChildClass1 : BaseClass {
  2. Q_OBJECT
  3. // etc..
  4. } ;
To copy to clipboard, switch view to plain text mode 
Qt Code:
  1. ChildClass2 : BaseClass {
  2. Q_OBJECT
  3. // etc..
  4. } ;
To copy to clipboard, switch view to plain text mode 

And for each class I declared and defined default constructor, copy constructor, assignment operator overload, and friend << and >> operators for QDataStream support.

Now, I have a list of BaseClass pointers used as follow :
Qt Code:
  1. void saveData(QDataStream & stream)
  2. {
  3. QList<BaseClass*> objList ;
  4. objList.append( new ChildClass1() ) ;
  5. objList.append( new ChildClass2() ) ;
  6. stream << objList.length() ;
  7. foreach(BaseClass *obj, objList)
  8. {
  9. stream << (*obj) ;
  10. }
  11. }
To copy to clipboard, switch view to plain text mode 

So when I serialize this list, how do I make sure it's actually ChildClass1 or ChildClass2 instances beeing serialized ? stream operators are non-member functions, so they cannot be virtual.

The same way when I de-serialize objects, (I must be blind but) I'm stuck with the following :
Qt Code:
  1. void readData(QDataStream & stream)
  2. {
  3. int i, count ;
  4. QList<BaseClass*> someList ;
  5. stream >> count ;
  6. for(i=0; i<count; i++)
  7. {
  8. stream >> ...// now what do I do here ?
  9. }
  10. }
To copy to clipboard, switch view to plain text mode 

Long story short, how do I combine Qt serialization and class inheritance ?

Any pointer would be greatly appreciated