I have a problem with serializing my objects on disk. This is a simplified scenario:
I have an ObjectA that provides its own serialization operators. They work, since I can save / load data to a file. Then I have an ObjectB containing ObjectA as a data member. Trying to save an ObjectB object, I got a runtime error:
QVariant :: save: cannot save type 279.
I use this code for stream statements:
QDataStream & operator<<( QDataStream & dataStream, const ObjectA & objectA )
{
for(int i=0; i< objectA.metaObject()->propertyCount(); ++i) {
if(objectA.metaObject()->property(i).isStored(&objectA)) {
dataStream << objectA.metaObject()->property(i).read(&objectA);
}
}
return dataStream;
}
QDataStream & operator>>(QDataStream & dataStream, ObjectA & objectA) {
QVariant var;
for(int i=0; i < objectA.metaObject()->propertyCount(); ++i) {
if(objectA.metaObject()->property(i).isStored(&objectA)) {
dataStream >> var;
objectA.metaObject()->property(i).write(&objectA, var);
}
}
return dataStream;
}
(just replace A with B for ObjectB statements)
I think the error is in implementing ObjectB serialization, but I do not know how to do this.
source
share