View Full Version : QHash<QString, QVarant> to file
weaver4
6th February 2010, 17:03
I would like to serialize and deserialize a QHash<QString , QVariant> to a file. Is there an easy way to do this?
weaver4
6th February 2010, 18:29
How about something like this:
QHash<QString, QVariant> entries;
entries.insert("key1", 1);
entries.insert("key2", "seven");
entries.insert("key3", 22.7);
QFile fileOut("hashtest.dat");
if (fileOut.open(QIODevice::WriteOnly))
{
QDataStream out(&fileOut);
out.setVersion(QDataStream::Qt_4_6);
out << entries;
fileOut.flush();
fileOut.close();
}
QHash<QString, QVariant> inputs;
QFile fileIn("hashtest.dat");
if (fileIn.open(QIODevice::ReadOnly))
{
QDataStream in(&fileIn);
in.setVersion(QDataStream::Qt_4_6);
in >> inputs;
fileIn.close();
}
franz
9th February 2010, 06:54
If it works, it's OK right?*
*Disclaimer: if it works it might still be wrong. It looks OK though.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.