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. Binary file handling using C functions
Forum Update on Monday, May 27th 2025

Binary file handling using C functions

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 453 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.
  • P Offline
    P Offline
    Parthasaradhi
    wrote on 18 Aug 2019, 12:34 last edited by
    #1

    Hi All,
    I am used to coding in C and started learning Qt recently. I have seen some posts on binary file handling but to me, it appeared quite cumbersome (also my knowledge on C++ classes and function is pretty limited. I used the old _open, _read, and _write functions and was able to do just what I wanted. However, I am not sure if the above functions are deprecated (I searched but could not really find). If these are not deprecated, I would like to use them as they are pretty straight forward. My question is, is this an accepted method? Does Qfile object offer better leverage in terms of handling the data (generally my binary data is in the form of structures). I read in one post that structure needs to be serialized, etc. Highly appreciate any comments on the above. Thanks.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      Kent-Dorfman
      wrote on 18 Aug 2019, 16:36 last edited by
      #2

      There will be real ramp-up time to learn C++ and use it effectivley, even if you already know C. Unless there is a reason to, I would discourage using C/POSIX functions when there are C++ or framework tools that are available. I think you've got a bit of self-instruction to do before jumping right into C++ file coding.

      std::C++ streams and file IO
      Qt streams and file IO
      object serialization
      effective class use and inheritance

      these are all things you need to teach yourself.

      1 Reply Last reply
      4
      • P Offline
        P Offline
        Parthasaradhi
        wrote on 19 Aug 2019, 03:34 last edited by
        #3

        Hi Kent-Dorfman,
        Thank you very much for your advice. Just for clarification, is there any specific reason to not to use C/POSIX function calls? I await your reply. Thanks once again.

        K 1 Reply Last reply 19 Aug 2019, 06:20
        0
        • P Parthasaradhi
          19 Aug 2019, 03:34

          Hi Kent-Dorfman,
          Thank you very much for your advice. Just for clarification, is there any specific reason to not to use C/POSIX function calls? I await your reply. Thanks once again.

          K Offline
          K Offline
          Kent-Dorfman
          wrote on 19 Aug 2019, 06:20 last edited by Kent-Dorfman
          #4

          @parthasaradhi

          Fair enough. A best-practice comp-sci paradigm is to use the highest level construct that meets the requirements. The C++ and Qt framework classes abstract the operations to a higher and arguably more intuitive level.

          I've written plenty of C++ wrapper classes around POSIX code over the years, but then learned the pure C++ mechanisms and they were better tested and easier for others to understand when they have to look at it.

          Also, the higher level constructs will usually be more platform neutral, which reduces rework when you have to port to a different platform.

          P 1 Reply Last reply 20 Aug 2019, 11:00
          0
          • J Offline
            J Offline
            JonB
            wrote on 19 Aug 2019, 06:30 last edited by
            #5

            @parthasaradhi
            I used to be a C programmer, and could happily use _open/read/write etc. level functions (or the C stdio wrappers to them). However, they are no longer the right level to use for new programs. As @Kent-Dorfman has indicated, you could use either the C++ functions or the Qt ones, either would be acceptable. For file handling they are not hard to learn, spend a few minutes looking through either and you should be good to go.

            1 Reply Last reply
            0
            • K Kent-Dorfman
              19 Aug 2019, 06:20

              @parthasaradhi

              Fair enough. A best-practice comp-sci paradigm is to use the highest level construct that meets the requirements. The C++ and Qt framework classes abstract the operations to a higher and arguably more intuitive level.

              I've written plenty of C++ wrapper classes around POSIX code over the years, but then learned the pure C++ mechanisms and they were better tested and easier for others to understand when they have to look at it.

              Also, the higher level constructs will usually be more platform neutral, which reduces rework when you have to port to a different platform.

              P Offline
              P Offline
              Parthasaradhi
              wrote on 20 Aug 2019, 11:00 last edited by
              #6

              @kent-dorfman Thank you for your reply.

              1 Reply Last reply
              0
              • P Offline
                P Offline
                Parthasaradhi
                wrote on 20 Aug 2019, 11:21 last edited by
                #7

                @jonb Thank you very much for your advice.

                1 Reply Last reply
                0

                1/7

                18 Aug 2019, 12:34

                • Login

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