Results 1 to 4 of 4

Thread: Missng last lines when read file wth readLine()

  1. #1
    Join Date
    Jan 2012
    Location
    Canary Islands, Spain
    Posts
    86
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Missng last lines when read file wth readLine()

    Hi, i'm trying to read a entire file:

    Qt Code:
    1. QFile lista(path);
    2. if(!lista.open(QFile::ReadOnly))
    3. {
    4. QMessageBox msgBox;
    5. msgBox.setText(tr("Could not open file.(2)"));
    6. msgBox.setStandardButtons(QMessageBox::Ok);
    7. msgBox.exec();
    8. } else {
    9. QTextStream strim(&lista);
    10.  
    11. while(!lista.atEnd()) {
    12. qDebug() << strim.readLine();
    13. }
    14. }
    15. lista.close();
    To copy to clipboard, switch view to plain text mode 

    But i can't read the last lines, it never read the last lines of files, sometimes 50, sometimes 100,.....

    What can be wrong??
    Last edited by aguayro; 20th August 2012 at 03:22.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,590
    Thanks
    13
    Thanked 1,586 Times in 1,515 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Missng last lines when read file wth readLine()

    What can be wrong??
    Almost anything:
    • You could be reading a file other than the one you think you are.
    • You could be reading a file that is being appended to by another process, so by the time you check the file is has more content.
    • You could be reading a binary file where the concept of "line" in meaningless.
    • You could could be reading a file with old-style Mac OS line endings expecting these to be treated as line endings.
    • You could just be mistaken about what is actually read.

  3. #3
    Join Date
    Aug 2009
    Location
    Greece
    Posts
    69
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Missng last lines when read file wth readLine()

    from QTextStream documentation:
    Since the text stream uses a buffer, you should not read from the stream using the implementation of a superclass. For instance, if you have a QFile and read from it directly using QFile::readLine() instead of using the stream, the text stream's internal position will be out of sync with the file's position.
    So maybe you should use " while (!strim.atEnd()) " to check the end of file

  4. #4
    Join Date
    Jan 2012
    Location
    Canary Islands, Spain
    Posts
    86
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Missng last lines when read file wth readLine()

    thanks, its working fine now

Similar Threads

  1. Autorepeat within eventfilter
    By Patrick_Bao in forum Qt Programming
    Replies: 0
    Last Post: 1st December 2010, 08:37
  2. Replies: 6
    Last Post: 14th October 2010, 07:58
  3. QTreeWidget and eventFilter
    By luoyes in forum Qt Programming
    Replies: 2
    Last Post: 5th November 2009, 07:38
  4. sceneEventFilter or eventFilter
    By zgulser in forum Qt Programming
    Replies: 7
    Last Post: 4th May 2009, 08:50
  5. paintEvent in eventFilter
    By kernel_panic in forum Qt Programming
    Replies: 1
    Last Post: 10th October 2007, 21:59

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.