Using Qt, I am opening a file for read-write access, first reading some content, then seeking back in the stream and writing some new data. When I close the file, I'd like to truncate it at the current file position. Currently, I do it with a f.resize(f.pos()) and wonder whether there is a simpler way to achieve this:
QFile f(filename);
if(f.open(QFile::ReadWrite)) {
QTextStream str(&f);
// do some reading from str here
f.reset();
// write some stuff to str here
f.resize(f.pos());
} else
qDebug() << "Could not open file" << it->filename();
f.close();
Using Qt::Truncate already truncates the file before reading, which is not what I want.