Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    How to write QByteArray to Position 0

    General and Desktop
    4
    9
    2118
    Loading More Posts
    • 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
      gandiii last edited by

      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 Reply Quote 0
      • I
        imihajlov last edited by

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

        1 Reply Last reply Reply Quote 0
        • A
          AlekseyOk last edited by

          .

          1 Reply Last reply Reply Quote 0
          • B
            broadpeak last edited by

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

            1 Reply Last reply Reply Quote 0
            • G
              gandiii last edited by

              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 Reply Quote 0
              • A
                AlekseyOk last edited by

                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 Reply Quote 0
                • I
                  imihajlov last edited by

                  The data will be overwritten after seeking to 0.

                  1 Reply Last reply Reply Quote 0
                  • B
                    broadpeak last edited by

                    [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 Reply Quote 0
                    • B
                      broadpeak last edited by

                      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 Reply Quote 0
                      • First post
                        Last post