Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How do I work with raw binary files with QT
Forum Updated to NodeBB v4.3 + New Features

How do I work with raw binary files with QT

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 502 Views 1 Watching
  • 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.
  • A Offline
    A Offline
    AI_Messiah
    wrote on 1 Aug 2021, 02:42 last edited by
    #1

    I don't want to do stuff with classes and different variables. I want to work with byte to byte. It has been hard to find it and I think that QT probably expects people to do it differently.

    J 1 Reply Last reply 1 Aug 2021, 05:58
    0
    • A AI_Messiah
      1 Aug 2021, 02:42

      I don't want to do stuff with classes and different variables. I want to work with byte to byte. It has been hard to find it and I think that QT probably expects people to do it differently.

      J Offline
      J Offline
      JonB
      wrote on 1 Aug 2021, 05:58 last edited by
      #2

      @AI_Messiah
      What do you mean by this question? Classes/variables have nothing to do with "byte to byte" and/or "raw binary files".

      Qt allows you to read/write binary files via QFile.

      If by any chance you are talking about file serialization/deserialization of variables/structures, you can use QFile directly, you do not have to go via QDataStream.

      1 Reply Last reply
      3
      • A Offline
        A Offline
        AI_Messiah
        wrote on 1 Aug 2021, 17:30 last edited by
        #3

        What I mean is that I want to read and write binary files. In a way that I know that the compiler will not add extra stuff. I want to read and write as char s and know that what I am working with is actually is what is in the file.

        C 1 Reply Last reply 1 Aug 2021, 17:48
        0
        • A AI_Messiah
          1 Aug 2021, 17:30

          What I mean is that I want to read and write binary files. In a way that I know that the compiler will not add extra stuff. I want to read and write as char s and know that what I am working with is actually is what is in the file.

          C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 1 Aug 2021, 17:48 last edited by
          #4

          @AI_Messiah So use QFile as @JonB already suggested.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          3
          • S Offline
            S Offline
            SimonSchroeder
            wrote on 2 Aug 2021, 08:50 last edited by
            #5

            @AI_Messiah said in How do I work with raw binary files with QT:

            I want to read and write as char s and know that what I am working with is actually is what is in the file.

            Qt does not add anything extra when accessing binary files. Just use it. However, to be precise a char is not necessarily 8 bits in C++ (https://stackoverflow.com/a/9727504/6954968). Qt uses QByteArray instead. I assume that on all platforms a single byte in QByteArray always has 8 bits. If you read the documentation carefully, QFile and QByteArray will do exactly what you want.

            1 Reply Last reply
            2

            1/5

            1 Aug 2021, 02:42

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved