Maybe the data isn't flushed to the byte array yet? See if this works:
#include <QtCore/QCoreApplication>
#include <QHash>
#include <QVariant>
#include <QDebug>
int main(int argc, char *argv[])
{
QHash<QString,QVariant> hash;
hash.insert("Key1",1);
hash.insert("Key2","thing2");
{
ds << hash;
} // here the stream gets destroyed so it has to flush whatever it caches
qDebug() << ba;
}
#include <QtCore/QCoreApplication>
#include <QHash>
#include <QVariant>
#include <QDebug>
int main(int argc, char *argv[])
{
QHash<QString,QVariant> hash;
hash.insert("Key1",1);
hash.insert("Key2","thing2");
QByteArray ba;
{
QDataStream ds(&ba, QIODevice::WriteOnly);
ds << hash;
} // here the stream gets destroyed so it has to flush whatever it caches
qDebug() << ba;
}
To copy to clipboard, switch view to plain text mode
Bookmarks