Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QDataStream default LittleEndian
Qt 6.12 LTS is out! See what's new in the release blog

QDataStream default LittleEndian

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 680 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    OPit
    wrote on last edited by OPit
    #1

    Hi,
    till today, use QDatastream was not a problem, it writes data in BigEndian by default.
    But I want to create a binary file and Qt write it in LittleEndian format. And if I force it with setByteOrder(QDataStream::BigEndian), it keeps LittleEndian format.

    Someone has already this problem ?

    QFile f("D:/Temp/camera.dat");
    f.open(QIODevice::WriteOnly);
    QDataStream str(&f);
    str.setByteOrder(QDataStream::BigEndian);
    int test = 1080;
    str.writeRawData(reinterpret_cast<char*>(&test), sizeof(int));
    f.close();
    

    I use W11 and Qt 6.4.2

    Thanks

    jsulmJ 1 Reply Last reply
    0
    • O OPit

      Hi,
      till today, use QDatastream was not a problem, it writes data in BigEndian by default.
      But I want to create a binary file and Qt write it in LittleEndian format. And if I force it with setByteOrder(QDataStream::BigEndian), it keeps LittleEndian format.

      Someone has already this problem ?

      QFile f("D:/Temp/camera.dat");
      f.open(QIODevice::WriteOnly);
      QDataStream str(&f);
      str.setByteOrder(QDataStream::BigEndian);
      int test = 1080;
      str.writeRawData(reinterpret_cast<char*>(&test), sizeof(int));
      f.close();
      

      I use W11 and Qt 6.4.2

      Thanks

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      @OPit said in QDataStream default LittleEndian:

      str.writeRawData(reinterpret_cast<char*>(&test), sizeof(int));

      Why don't you do instead:

      str << test;
      

      ?
      There is no byte order for a byte array.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      O 2 Replies Last reply
      1
      • jsulmJ jsulm

        @OPit said in QDataStream default LittleEndian:

        str.writeRawData(reinterpret_cast<char*>(&test), sizeof(int));

        Why don't you do instead:

        str << test;
        

        ?
        There is no byte order for a byte array.

        O Offline
        O Offline
        OPit
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • jsulmJ jsulm

          @OPit said in QDataStream default LittleEndian:

          str.writeRawData(reinterpret_cast<char*>(&test), sizeof(int));

          Why don't you do instead:

          str << test;
          

          ?
          There is no byte order for a byte array.

          O Offline
          O Offline
          OPit
          wrote on last edited by
          #4

          @jsulm Oh thank you. I believed Qt was adding pseudo data when use << .

          Perfect, it's resolved (even if I don't know why LittleEndian is always used with writeRawData)

          jsulmJ 1 Reply Last reply
          0
          • O OPit has marked this topic as solved on
          • O OPit

            @jsulm Oh thank you. I believed Qt was adding pseudo data when use << .

            Perfect, it's resolved (even if I don't know why LittleEndian is always used with writeRawData)

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by jsulm
            #5

            @OPit said in QDataStream default LittleEndian:

            why LittleEndian is always used with writeRawData

            Because writeRawData writes a bunch of bytes and byte order is not relevant for it. Byte order is only relevant for things like integers, floats, ... (for data types bigger than one byte).

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt
            • Unsolved