Re: reading wrong data from QByteArray
Hi all,
This is short code , which is not giving me what I expect. I dump two integers ( 4 , 8 ) in a QByteArray and when I read them with QDataStream I am getting unexpected values -- 67108864 , 134217728.
What am I doing wrong here?...
Code:
int numPts = 4;
int numCells = 8;
int sizeOfChar = sizeof( char );
int sizeOfInt = sizeof( int );
array.
append( QByteArray::fromRawData ( reinterpret_cast<const
char*>
( &numPts
), sizeOfInt
/ sizeOfChar
) );
array.
append( QByteArray::fromRawData ( reinterpret_cast<const
char*>
( &numCells
), sizeOfInt
/ sizeOfChar
) );
int readNumPts , readNumCells;
streamOut >> readNumPts >> readNumCells;
std::cout<<readNumPts<<" "<<readNumCells<<std::endl;
Regards
Avanindra Singh
I still don't know the reason for the above code not working , but writing data with QDataStream into QByteArray gave correct results.
Code:
int numPts = 4;
int numCells = 8;
int sizeOfChar = sizeof( char );
int sizeOfInt = sizeof( int );
streamIn << numPts << numCells;
int readNumPts , readNumCells;
streamOut >> readNumPts >> readNumCells;
Re: reading wrong data from QByteArray
QDataStream is not a general purpose binary stream. It is a serialization mechanism.
Re: reading wrong data from QByteArray
Re: reading wrong data from QByteArray
Quote:
Originally Posted by
ChrisW67
Two words; byte order.
one word: Endianness :eek: