Question regarding Big/Little endian



  • We recently ran into an issue running on an older PowerPC platform. All of our code assumes little-endian byte order, but the PowerPC is a big-endian platform by default, so we had some problems.

    I am writing some new socket code and want to ensure that I don't introduce any new issues. Looking at the Qt5.5 version of the Fortune client/server example, the fortune is streamed with a qint16 message header which specifies the size of the packet.

    How will this behave if I am communicating between a little-endian and a big-endian platform?



  • from http://doc.qt.io/qt-5/qdatastream.html

    A data stream is a binary stream of encoded information which is 100% independent of the host computer's operating system, CPU or byte order. For example, a data stream that is written by a PC under Windows can be read by a Sun SPARC running Solaris.

    You should be fine



  • @VRonin thanks!


  • Qt Champions 2016

    By default QDataStream uses big endian. You can change it manually, but do so on all platforms you want to deploy to/programs you're deploying. In any case you're fine as long as you stream your data with the appropriate operators and don't use writeRawData/readRawData or any reinterpret_cast "tricks".


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.