简体   繁体   English

Qt C ++继续文件而不是覆盖

[英]Qt C++ Continuing a File and not Overwriting

I'm writing a program in Qt C++ to create a sort of database. 我正在Qt C ++中编写程序来创建一种数据库。 However, whenever I hit the push button it overwrites the entire file instead of continuing to a new line like I need it to do. 但是,每当我按下按钮时,它都会覆盖整个文件,而不是像我需要的那样继续到新行。 I would really appreciate any info on how to fix this. 我非常感谢有关如何解决此问题的任何信息。

Relevant Code Portion: 相关代码部分:

QFile file("C:/Users/brandan/Desktop/GUIPrograms/Kumon.txt");
file.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream stream(&file); //stream of information
stream << " " << endl;
stream << name << " " << month << " " << day << " " << year << " " << page << endl;
file.close();

您必须以追加模式打开文件:

file.open(QIODevice::Append | QIODevice::Text);

Did you try QIODevice::Append ? 您尝试过QIODevice::Append吗?

By the way, this has been asked a several times. 顺便说一句,这已经被问过几次了。 A simple google search gives this: Open QFile for appending 一个简单的谷歌搜索给出: 打开QFile追加

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM