When working with QTcpSocket I usually use this approach:
quint16 i;
// This function sets the byte order of incoming data; network format is BigEndian,
// while Intel format is LittleEndian
packet = socket->read(sizeof(i));
in >> i;
quint16 i;
QByteArray packet;
QDataStream in(&packet, QIODevice::ReadOnly);
// This function sets the byte order of incoming data; network format is BigEndian,
// while Intel format is LittleEndian
in.setByteOrder(QDataStream::BigEndian);
packet = socket->read(sizeof(i));
in >> i;
To copy to clipboard, switch view to plain text mode
I've learned this approach from "C++ GUI Programming with Qt 4", so I think it is the recommended one.
Bookmarks