0

I'm writing a program in Qt C++ to create a sort of database. 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();
Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
user3183403
  • 63
  • 1
  • 2
  • 8

2 Answers2

4

You have to open the file in append mode:

file.open(QIODevice::Append | QIODevice::Text);
David G
  • 94,763
  • 41
  • 167
  • 253
3

Did you try QIODevice::Append?

By the way, this has been asked a several times. A simple google search gives this: Open QFile for appending

Community
  • 1
  • 1
Jeremy D
  • 4,787
  • 1
  • 31
  • 38