[Qt-interest] Program crashing when I read quint32 from QDataStream

Jason H scorp1us at yahoo.com
Thu Mar 10 20:37:46 CET 2011


When you change the storage size for compressionCode, make sure you change the 
data in your stream to be 4 bytes, not 2. Else, you'll get a short read, or in 
this case, significantBitsPerSample will be attempted to read at EOF. Since 
you're reading from a QBuffer, that's a attempted read past its memory buffer.







----- Original Message ----
From: Nicholas Shatokhin <n.shatokhin at gmail.com>
To: "qt-interest at qt.nokia.com" <qt-interest at qt.nokia.com>
Sent: Thu, March 10, 2011 1:27:35 AM
Subject: [Qt-interest] Program crashing when I read quint32 from QDataStream

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?


-- 
За використання революційного клієнта електронної пошти Opera:  
http://www.opera.com/mail/
_______________________________________________
Qt-interest mailing list
Qt-interest at qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-interest



      



More information about the Qt-interest-old mailing list