Results 1 to 2 of 2

Thread: Remove a line in a text file

  1. #1
    Join Date
    Dec 2007
    Location
    Brazil
    Posts
    61
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Remove a line in a text file

    How to remove a line from a file?

    Qt Code:
    1. void DeslocaPt::skip(QStringList &l, QStringList &p)
    2. {
    3. QString arqAlt = altEdit->text();
    4. QString line, linesimp;
    5. QFile file(arqAlt);
    6. if(file.open(QIODevice::ReadWrite | QIODevice::Text)){
    7. QTextStream out(&file);
    8. while(!out.atEnd()){
    9. line = out.readLine();
    10. linesimp = line.simplified();
    11. for (int i = 0; i < l.size(); ++i)
    12. if (linesimp.contains(QString("S%1 %2").arg(l.at(i)).arg(p.at(i)))){
    13. line.clear();
    14. }
    15.  
    16. out << line << endl;
    17. }
    18. }
    19. file.close();
    20. }
    To copy to clipboard, switch view to plain text mode 

    I tried to do:
    Qt Code:
    1. line.clear();
    2. out << line << endl;
    To copy to clipboard, switch view to plain text mode 
    I used this command to position
    Qt Code:
    1. out.seek(out.pos() - line.size() );
    To copy to clipboard, switch view to plain text mode 
    result is not satisfactory. Any idea?

  2. #2
    Join Date
    Dec 2007
    Location
    Brazil
    Posts
    61
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Remove a line in a text file

    I think there is not a quicker solution to delete a row in a given file. The solution was to add two QFile, one for ReadOnly and another to WriteOnly.

Similar Threads

  1. Replies: 8
    Last Post: 8th May 2012, 09:39
  2. QTextStream : Remove a Line?
    By kaydknight in forum Qt Programming
    Replies: 7
    Last Post: 31st January 2011, 18:15
  3. How to read line number in a text file
    By grsandeep85 in forum Qt Programming
    Replies: 7
    Last Post: 31st July 2009, 09:09
  4. Replies: 1
    Last Post: 10th March 2008, 17:51
  5. Replies: 2
    Last Post: 17th November 2006, 11:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.