Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Write a txt doc
Qt 6.11 is out! See what's new in the release blog

Write a txt doc

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rcaji
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      open the file with QIODevice::Append mode.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved