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:
    @ 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&#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.


  • 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.