# Write a txt doc

• 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:
{
QFile file(filename);
QString linea;

``````if(!file.open(QFile::ReadOnly | QFile::Text)
{
return;
}
QTextStream in(&file);

while(!in.atEnd())
{
qDebug() << linea;
}
file.close();

void writeDoc(QString filename, QString text)
{
QFile file&#40;filename&#41;;
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.