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?

    @ void readDoc(QString filename)
    QFile file(filename);
    QString linea;

    if(!file.open(QFile::ReadOnly | QFile::Text)
    QTextStream in(&file);
    linea = in.readLine();
    qDebug() << linea;
    void writeDoc(QString filename, QString text)
    QFile file&#40;filename&#41;;
    QTextStream out(&file);
    if(!file.open(QFile::WriteOnly | QFile::Text)
    out << text;

    The value of text is the text of the lineEdit.

  • Moderators

    open the file with QIODevice::Append mode.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.