Question

Is there a way that I can always append new text into the beginning of a text file in Qt? i'm using QFile::Append to do it.

file.open(QFile::Append | QFile::Text)
Was it helpful?

Solution

You can't, see the documentation at http://doc.qt.io/qt-5/qiodevice.html:

QIODevice::Append 0x0004 The device is opened in append mode, so that all data is written to the end of the file.

The problem is even worse, a file is usually stored sequentially on disk, appending (better: inserting) at the start of a file would involve moving all data towards the end of the file, thus a reorganization of filesystem blocks. I'm not sure such a filesystem exists, but if, I guess it would only allow insertion of a multiple of the filesystem block size into a file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top