Results 1 to 3 of 3

Thread: QTextStream not reading the entire file

  1. #1
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QTextStream not reading the entire file

    I am trying to read a text file line by line. File has got 695 lines of text but for some reason QTextStream only reads up to 501 lines and anything after that is not read. Here is my code below.
    Qt Code:
    1. void read(QString path1)
    2. {
    3. QFile rfile(path1);
    4.  
    5. if(!rfile.open(QFile::ReadOnly | QFile::Text))
    6. {
    7. qDebug() << "File did not open" <<endl;
    8. return;
    9. }
    10.  
    11. QTextStream in(&rfile);
    12. stringList.clear();
    13.  
    14. while(!rfile.atEnd())
    15. {
    16. QString trwCode = in.readLine(0);
    17. if(trwCode.contains("http://"))
    18. trwCode.remove(0, 7);
    19. else if(trwCode.contains("https://"))
    20. trwCode.remove(0, 8);
    21.  
    22. qDebug() <<trwCode <<endl;
    23.  
    24. stringList.append(trwCode);
    25.  
    26. trwCode.clear();
    27.  
    28. }
    29.  
    30. rfile.flush();
    31. rfile.close();
    32. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextStream not reading the entire file

    Change line 14 to :
    Qt Code:
    1. while(!in.atEnd())
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to Lesiok for this useful post:

    ayanda83 (18th October 2016)

  4. #3
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTextStream not reading the entire file

    Lol, it works. thanks

Similar Threads

  1. Reading from QFile when QTextStream is open
    By dawwin in forum Qt Programming
    Replies: 2
    Last Post: 19th March 2011, 17:43
  2. reading Continously from QTextStream
    By babu198649 in forum Newbie
    Replies: 2
    Last Post: 2nd December 2008, 11:15
  3. QTextStream loses position while reading file
    By bjh in forum Qt Programming
    Replies: 2
    Last Post: 13th February 2008, 15:47
  4. reading from QTextStream
    By matyi52 in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 14th December 2006, 07:26
  5. Reading File using QFile and QTextStream
    By atm in forum Qt Programming
    Replies: 4
    Last Post: 13th July 2006, 23:12

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.