So im at a bit of a loss and im hoping someone here can help.
My object being serialized looks like this
QHash<QString, QHash<QString, QHash<QString, QVariant>*>*>* hosthash = new QHash<QString, QHash<QString, QHash<QString, QVariant>*>*>();
QHash<QString, QHash<QString, QHash<QString, QVariant>*>*>* hosthash = new QHash<QString, QHash<QString, QHash<QString, QVariant>*>*>();
To copy to clipboard, switch view to plain text mode
Then as my application is running the lowest level QHash<QString,QVariant> gets populated and all is good when it comes time to serialize, where i then nest it into a few more hashes to properly organize all the data.
At the lowest hash i have a deviceModel that contains all the data i want, which i wrap in another hash whose key differentiates that device from other devices on the system, and then that is wrapped once again in a hash whose key differentiates different systems. Its preferred to keep it this way because it will allow me to easily recreate a nested QTree with all the pertinent information(in theory).
I wrote two overridden >> operators for datastream to dereference the pointer and pass it into the stream.
stream << *deviceModelHash;
return stream;
}
stream << *deviceHash;
return stream;
}
QDataStream &operator <<(QDataStream &stream, const QHash<QString, QVariant>* deviceModelHash) {
stream << *deviceModelHash;
return stream;
}
QDataStream &operator <<(QDataStream &stream, const QHash<QString, QHash<QString, QVariant>*>* deviceHash) {
stream << *deviceHash;
return stream;
}
To copy to clipboard, switch view to plain text mode
All seems well, when i write it to a file it comes out to be 3100ish bytes which seems realistic for how much data im storing.
But the problem comes with Deserializing. Say i have another hash i want to read into that does not consist of pointers because its not needed when coming back in.
QHash<QString, QHash<QString, QHash<QString, QVariant>>> testhash
QHash<QString, QHash<QString, QHash<QString, QVariant>>> testhash
To copy to clipboard, switch view to plain text mode
How do i get this data back into a workable hash? I assume i need to make some sort datastream >> testHash override but i am confused how to go about doing that. Just doing datastream >> TestHash after opening the stream from file results in an empty testHash. But im at a loss for how to do it manually in the overridden >> function because of how nested the data is. I cant create the top level of the hash without knowing what the 2nd level of the hash is, and i cant create the 2nd level of the hash without having read in the 3rd level of the hash. Hopefully that makes sense?
Thanks.
Bookmarks