Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open QFile for appending

Tags:

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

FILE *f = fopen("myfile.txt", "a");
like image 722
sashoalm Avatar asked Dec 13 '12 09:12

sashoalm


People also ask

How do you write data in a QFile?

To write text, we can use operator<<(), which is overloaded to take a QTextStream on the left and various data types (including QString) on the right: QFile file("out. txt"); if (! file.

What is QFile QT?

QFile is an I/O device for reading and writing text and binary files and resources. A QFile may be used by itself or, more conveniently, with a QTextStream or QDataStream. The file name is usually passed in the constructor, but it can be set at any time using setFileName().

How do you save a QT file?

This way, the file must have a filename associated with it. So the first thing you have to do is create a Qt widget application. You will have to place 2 elements within this widget application: a text edit and a push button. We label the push button, 'Save As', as it functions as a 'Save As' button.


1 Answers

Open the file in QIODevice::Append mode:

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

See also the documentation.

like image 96
Maciej Avatar answered Oct 17 '22 03:10

Maciej