Results 1 to 3 of 3

Thread: Detecting the last empty line in a file

  1. #1
    Join Date
    Oct 2006
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Detecting the last empty line in a file

    Hi,
    i am writing a piece of code where i modify a file (add and remove entire lines).
    The problem is that i am unable to grab the last empty line. The current code is :
    Qt Code:
    1. QStringList file_text;
    2. while (!in.atEnd()) {
    3. QString line = in.readLine();
    4. file_text.push_back(line);
    5. }
    6. file.close();
    7. //processing the lines and then save
    To copy to clipboard, switch view to plain text mode 

    is there any way to get the last empty line ? (or at least to detect if there is one)

  2. #2
    Join Date
    Aug 2006
    Location
    Switzerland
    Posts
    52
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Detecting the last empty line in a file

    Well,
    Qt Code:
    1. if (line.size() != 0) {
    2. // do something
    3. }
    To copy to clipboard, switch view to plain text mode 
    should do the job, I guess.
    The Wheel weaves as the Wheel wills.

  3. #3
    Join Date
    Jul 2006
    Location
    Almaty/KAZAKHSTAN
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Detecting the last empty line in a file

    May be something like this:
    Qt Code:
    1. QStringList file_text;
    2. do {
    3. QString line = in.readLine();
    4. file_text.push_back(line);
    5. } while (!in.atEnd());
    6. file.close();
    7. //processing the lines and then save
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. read file from end to beginning..
    By soul_rebel in forum Qt Programming
    Replies: 11
    Last Post: 4th June 2012, 01:20
  2. QTableView paints too much
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2006, 18:42
  3. How to read line from file
    By Krishnacins in forum Newbie
    Replies: 10
    Last Post: 1st June 2006, 23:14
  4. QListWidget-problem
    By Sarma in forum Qt Programming
    Replies: 7
    Last Post: 7th April 2006, 18:49
  5. dialog box
    By Bahar in forum Qt Programming
    Replies: 3
    Last Post: 31st January 2006, 14:52

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.