Search code examples
qtqfile

How to write without overwrite in Qfile?


Hi guys I have this code but it just overwrite the file. How can I just add text to the file?

 QFile file("E:/Qt/Qt codes/txt file/file");
 if(!file.open(QFile::WriteOnly | QFile::Text)){ 
       QMessageBox::warning(this,"Title","File not open.");
 }
 QTextStream out(&file);
 QString text = ui->plainTextEdit_2->toPlainText();
 out << text;
 file.flush();
 file.close();
       

Thanks.


Solution

  • I think you can set flag QFile::Append

    QFile inherits QIODevice.

    here is doc.QIODevice Class