Ralf Wickum
Ralf Wickum

Reputation: 3270

How to serialize a QHash and a QMap in a single file?

I have a QHash and a seperate QMap. I can serialize them alone. But I would like to serilize them in a single file:

QMap<int,QString> myMap;
QHash<QString,MyCalss> myHash;
// .. fill: both have 4 (key,value) pairs.
// write here
QDataStream out (&myFile);
out<<myMap;
out<<myHash;
// read written
QDataStream in (&myFile);
in>>myMap>>myHash;

The last read (here myHash) is empty always. When I switch the ordering

QDataStream out (&myFile);
out<<myHash;
out<<myMap;
// read written
QDataStream in (&myFile);
in>>myHash>>myMap;

so here myMap is empty.

How can I serialize both simultaneously?

Upvotes: 0

Views: 510

Answers (1)

Jens
Jens

Reputation: 6329

Whats wrong with

QDataStream out (&myFile);
out<<myMap;
out<<myHash;
// read written
QDataStream in (&myFile);
in>>myMap;
in>>myHash;

Serializing 'in' into the Hash and the Hash into the Map will not lead to the desired results.

Upvotes: 1

Related Questions