Qt 6.11 is out! See what's new in the release
blog
Write a txt doc
General and Desktop
2
Posts
2
Posters
1.1k
Views
1
Watching
-
Hi,
I have the following problem, when I want to write to a txt document, I write only the last added. How could make it so when you go inserting text, this is written on the next line?code:
@ void readDoc(QString filename)
{
QFile file(filename);
QString linea;if(!file.open(QFile::ReadOnly | QFile::Text) { return; } QTextStream in(&file); while(!in.atEnd()) { linea = in.readLine(); qDebug() << linea; } file.close(); void writeDoc(QString filename, QString text) { QFile file(filename); QTextStream out(&file); if(!file.open(QFile::WriteOnly | QFile::Text) { return; } out << text; }@The value of text is the text of the lineEdit.
-
open the file with QIODevice::Append mode.