hi all,

i was struggling with putting a qstring into a qdatastream and getting it out again.
reading through the 4.0 docu's fortune client example it seemed to me that a QString str, when written to a QDataStream, needed str.length bytes.
but this is wrong. it should be 2*length + 4 (every letter in the string gets encoded with 2 bytes and the strings length goes at the beginning encoded with a 4 bytes int) right?

and another thing (which is actually my question) is the following:

Qt Code:
  1. // sender
  2. QDataStream stream(socket);
  3. stream << some_QString;
  4. stream << some_quint;
  5.  
  6. // receiver
  7. QDataStream stream(socket);
  8. stream >> some_QString;
To copy to clipboard, switch view to plain text mode 

i found out that in my case the receiver gets an exact copy of some_QString and that the following integer is not read. which makes sence after finding out that QString is serialized such that it carries its own length with it. but can i count on that? i'm sending strings followed by ints. so can i just read the strings like that:

Qt Code:
  1. stream >> some_QString;
To copy to clipboard, switch view to plain text mode 

when i know it is followed by an int. or should i still take care by myself that i dont mix up string and int??