Qt has a QFile::resize(bt) method that sets the file size to bt, cutting everything that goes on. Is there an analogue (and, in general, is it “legally” to do that), which cuts a file on bt from the beginning?

Context of the task: there is generally a third-party process that puts logs in the file file , so synchronize by accessing the file will not work. When I receive records, I need to read the file, parse everything that is written there, and cut the read data (written to another file). Of course, this is required to be done synchronously in order not to lose anything. So far I have thought of only the version voiced above.

  • Think about the last change tempo and the previous position in the file. - LLENN
  • why do you need to cut the read data? - goldstar_labs
  • @goldstar_labs so that when restarting my program to parse only that from the file that I have not touched, and add to my file. A file that is filled in by a third-party process is rotated daily - magrif
  • one
  • @avp how do these functions correlate with the truncation task from the beginning? - magrif

1 answer 1

Using any resize is impossible, since the data will be deleted from the end to the beginning. To delete data from the beginning to the end, you can use the position set method QFile :: seek (qint64). Then read and copy the data to a file.