Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-66674

qToBigEndian(src, dest) does not change byte order on little endian system.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P2: Important
    • None
    • 5.10.0
    • Core: Other
    • 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

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            jluedicke Jens Luedicke
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes