It seems that you're experiencing byte order problem. Since QUdpSocket
inherits QIODevice
, you can use QDataStream
on it, and this class supports byte order conversion. Specify the byte order of incoming data:
QDataStream stream(m_udpSocket);
stream.setByteOrder(QDataStream::BigEndian); // or LittleEndian
And then you can receive data like that:
unsigned int b;
stream >> b;
Also qToBigEndian
, qToLittleEndian
, qFromBigEndian
, qFromLittleEndian
functions may be useful.