Details
-
Bug
-
Resolution: Invalid
-
P2: Important
-
None
-
5.10.0
-
None
-
Qt 5.10.0 (x86_64-little_endian-llp64 shared (dynamic) debug build; by GCC 7.2.0)
Description
The qToBigEndian function does not produce the desired result.
I'm on a little endian machine (x86_64) using Qt 5.10.0 with Mingw64. A protocol requires a size value in big endian order and when I use qToBigEndian(src, dest) to write it into a QByteArray buffer, the buffer contains the value in little endian order:
const std::size_t oldSize = commandData.size(); const std::size_t newSize = oldSize + sizeof(T); commandData.resize(newSize); qToBigEndian(val, commandData.data() + oldSize);
val is a quint16
new length = 16
QINFO : TestFunctionCommands::testMakeCommand() "\x00\x10"
The value should be written as a 0x1000 and not as 0x0010.
FAIL! : TestFunctionCommands::testMakeCommand() Compared values are not the same
Actual (qToLittleEndian<quint16>(reinterpret_cast<quint16>(data.data()))): 4096
Expected (expectedSize) : 16