PDA

View Full Version : QDataStream doesn't work as expected



mastupristi
16th June 2010, 13:04
I have this sample code:

QDataStream *newDataSrteam;
QByteArray ba;

quint32 tag;
tag = 0x00;
newDataSrteam = new QDataStream(&ba, QIODevice::WriteOnly | QIODevice::Unbuffered);
newDataSrteam->setByteOrder(QDataStream::LittleEndian);

int i = 0;
while(i++<10)
{
ba.clear();
*newDataSrteam << (quint32)tag++;
printf("%s\n", ba.toHex().data());
}

and running I get the following output:

00000000
0000000001000000
303030303030303002000000
30303030303030300200000003000000
3030303030303030020000000300000004000000
303030303030303002000000030000000400000005000000
33303330333033303330333033303330303230303030303006 000000
33303330333033303330333033303330303230303030303006 00000007000000
33303330333033303330333033303330303230303030303006 0000000700000008000000
33303330333033303330333033303330303230303030303006 000000070000000800000009000000

I wonder what is wrong with my code...
what is happening? It seem that be is never cleared...

thanks

jjian
22nd June 2010, 07:08
you'd better to seek the current postion before to read data.