[Qt-interest] QTcpSocket & QDataStream
pmqt71
pmqt71 at gmail.com
Sat Feb 5 11:02:15 CET 2011
Hi,
I'm sending data from a client to a server using QTcpSocket just as
described in the fortune example. But when the server reads, it finds the
data shifted by 4 bytes (in wich I find the length of the QByteArray used in
the client side).
Something similar happens in the following example. QByteArray::data (or
constData) is the same used by QTcpSocket to write a QByteArray.
*QByteArray ba;*
*char *ss = NULL;*
* *
*QDataStream ds(&ba, QIODevice::WriteOnly);*
*ds << "hello";*
*ss = ba.data(); //ss is empty*
*ss += 4; //ss contains "hello"*
The first 4 bytes seems to contain the length of ba: 0,0,0,6
If I don't use QDataStream I have no extra bytes:
*QByteArray ba;*
*char *ss = NULL;*
* *
*ba.append("hello");*
*ss = ba.data(); //ss contains "hello"*
I should skip the first 4 bytes before reading my data (that already contain
a length), but I don't find the same instruction in the fortune example.
Where is the problem in my code?
Qt 4.6.2 on xp
thanks
pm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110205/0be53419/attachment.html
More information about the Qt-interest-old
mailing list