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:
// sender
stream << some_QString;
stream << some_quint;
// receiver
stream >> some_QString;
// sender
QDataStream stream(socket);
stream << some_QString;
stream << some_quint;
// receiver
QDataStream stream(socket);
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:
stream >> some_QString;
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??
Bookmarks