PDA

View Full Version : QDataStream and QHash<QString,QVariant> crash on read



^NyAw^
15th July 2008, 10:51
Hi,

I'm using Qt 4.3.0 on Windows with Visual Studio 2003 .NET.

I have a QHash defined as:


QHash<QString,QVariant> m_qHash;


The "m_qHash" containg 16 elements.

Then I use a QDataStream to store it to a file.
When trying to load from the file, the first value(hash pair) is correctly loaded,but it crash on "QDataStream &operator>>(QDataStream &in, QString &str)" into "qstring.cpp", when reading the second value(hash pair). When it reads the "bytes" on line 6829, it reads that it contains 0 bytes and so it returns an empty string.
Then on "QDataStream& operator>>(QDataStream &s, QVariant &p)" into "qvariant.cpp" crash on line 1775:



Q_ASSERT_X(false, "QVariant::load", "Invalid type to load");


I'm debugging the application and I don't find where is the problem.

Thanks,

^NyAw^
15th July 2008, 12:14
Hi,

I've found my error:

I was setting the QDataStream version to Qt 4.1 on writting but I've forgiven to set the same version on the QDataStream when reading. So, as I updated the Qt version from 4.1 to 4.3 it crashed.

Thanks,