如何在Qfile中写入而不覆盖?

How to write without overwrite in Qfile?

大家好,我有这段代码,但它只是覆盖了文件。我怎样才能向文件中添加文本?​​

 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();
       

谢谢。

我想你可以设置标志QFile::Append

QFile 继承 QIODevice.

这是文档QIODevice Class