22

How can I open a QFile for appending, i.e. the equivalent of

FILE *f = fopen("myfile.txt", "a");
sashoalm
  • 75,001
  • 122
  • 434
  • 781

1 Answers1

50

Open the file in QIODevice::Append mode:

QFile f(...);
if (f.open(QIODevice::WriteOnly | QIODevice::Append)) {
  ...
}

See also the documentation.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
Maciej
  • 3,685
  • 1
  • 19
  • 14
  • 12
    The Qt documentation is misleading: "The mode must be QIODevice::ReadOnly, QIODevice::WriteOnly, or QIODevice::ReadWrite. It may also have additional flags, such as QIODevice::Text and QIODevice::Unbuffered." QIODevice documentation mentions the Append flag, but it not apparent from just looking at the QFile documentation. – Ken A May 14 '14 at 15:49