[Qt-interest] Program crashing when I read quint32 from QDataStream
Tony Rietwyk
tony.rietwyk at rightsoft.com.au
Thu Mar 10 23:57:57 CET 2011
Hi Nicholas,
I'm not sure about the specific error message. Have you read the QDataStream docs? If the file was not written via QDataStream, then you can only use readRawData on it.
I don't understand why there isn't a more restricted QBinaryStream that behaves the way you are expecting - it seems to be a common mistake!
Hope that helps,
Tony.
> -----Original Message-----
> Sent: Thursday, 10 March 2011 17:28
>
> Look the code:
>
> quint16 compressionCode;
> quint16 numberOfChannels;
> quint32 sampleRate;
> quint32 averageBytesPerSecond;
> quint16 blockAlign;
> quint16 significantBitsPerSample;
>
> QBuffer buffer(&fileData);
>
> buffer.open(QIODevice::ReadOnly);
>
> QDataStream stream(&buffer);
> stream.setByteOrder(QDataStream::LittleEndian);
>
> stream >> compressionCode;
> stream >> numberOfChannels;
> stream >> sampleRate;
> stream >> averageBytesPerSecond;
> stream >> blockAlign;
> stream >> significantBitsPerSample;
>
> buffer.close();
>
> Programs successfully read all data, but when it try to exit - it's
> crashing. If I change type of all variables to quint16 - it's
> works. If I
> change type of compressionCode to quint32 - it's writing
> message: "pure
> virtual method called
> terminate called without an active exception"
>
> What is wrong?
More information about the Qt-interest-old
mailing list