QDataStream is a class for serializing objects. But it can append its own info about serializing object. So don't expect it would be byte to byte what you want. It is made in such way that when you write something to QDataStream (with operator <<) and then you can read it from it on the other end (with operator >>) then you get the same. But who cares what is in the middle :] A little example : let's say you have a QString str("Hello"); then you write it to QDataStream object. In this stream the QDataStream can do whateveer it wants it can even append " World!" to your string :] but when you read string fron QDataStream it returns what you wrote: QString("Hello"). So if you want to have a QByteArray containing only your own data then put every byte of your data separately. For example, if you have an 32-bit integer you can do:
Qt Code:
  1. int num = 158;
  2. for (int i = 0; i < 4; ++i) {
  3. ba += quint8((num >> i*8) & 0x000000ff);
  4. }
To copy to clipboard, switch view to plain text mode 
and now you have every byte of your int written to byte array. Then you have to construct one int from 4 bytes from byte array on the other side.