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 to write QByteArray to Position 0
Forum Updated to NodeBB v4.3 + New Features

How to write QByteArray to Position 0

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 2.6k 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.
  • G Offline
    G Offline
    gandiii
    wrote on last edited by
    #1

    hi,

    does anybody know how I can write a QByteArray at Position 0 (start)
    of a file. (i want to create a header)

    It is an embedded system so I have not enough memory
    to read the whole file and append it to the header array.

    thx

    1 Reply Last reply
    0
    • I Offline
      I Offline
      imihajlov
      wrote on last edited by
      #2

      You may shift the file chunk-by-chunk, saving these small amounts of data into a small buffer.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AlekseyOk
        wrote on last edited by
        #3

        .

        1 Reply Last reply
        0
        • B Offline
          B Offline
          broadpeak
          wrote on last edited by
          #4

          bool QFile::seek ( qint64 pos ) can't help?

          1 Reply Last reply
          0
          • G Offline
            G Offline
            gandiii
            wrote on last edited by
            #5

            if I write seek(0) and then write(data) will the data be written
            to this place whithout deleting the existing data?

            1 Reply Last reply
            0
            • A Offline
              A Offline
              AlekseyOk
              wrote on last edited by
              #6

              from doc of QFile::seek()

              bq. If a write is performed at this position, then the file shall be extended. The content of the file between the previous end of file and the newly written data is UNDEFINED and varies between platforms and file systems.

              1 Reply Last reply
              0
              • I Offline
                I Offline
                imihajlov
                wrote on last edited by
                #7

                The data will be overwritten after seeking to 0.

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  broadpeak
                  wrote on last edited by
                  #8

                  [quote author="gandiii" date="1353589552"]if I write seek(0) and then write(data) will the data be written
                  to this place whithout deleting the existing data?[/quote]

                  As I know, the seek() only put your "cursor" into a given position.
                  If your position is IN a filled dataarea, your write() will overwrite that data. Anyway you will write into a virgin area...

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    broadpeak
                    wrote on last edited by
                    #9

                    Another solution: use the QTemporaryFile write the header here, and after this, you can append the second file after the first temporary file, or something similar ...

                    1 Reply Last reply
                    0

                    • Login

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