Results 1 to 2 of 2

Thread: Progress of reading the file

  1. #1
    Join Date
    Nov 2007
    Location
    Russia, Moscow
    Posts
    21
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Progress of reading the file

    I read the input text file line by line.
    Qt Code:
    1. dataFile = new QFile(fileName);
    2. dataFile->open(QIODevice::ReadOnly | QIODevice::Text);
    3. dataStream = new QTextStream(dataFile);
    4. while( !dataStream->atEnd() ) {
    5. line = dataStream->readLine();
    6. ...
    7. }
    To copy to clipboard, switch view to plain text mode 
    The file is > 200Mb.
    I need to update a progress bar while i analize the lines.
    I was going to use
    Qt Code:
    1. 100 * currentLine / numberOfLines
    To copy to clipboard, switch view to plain text mode 
    but how do i get the number of lines in the file?..

    Thx!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Progress of reading the file

    You can't. You'd have to read the file first and count newline characters What you can do is to calculate an average line length based on the file size. A simple approximation is to calculate not lines but bytes in the file assuming that each line has more or less similar number of characters.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Windows file copy in progress, how can I tell?
    By tgreaves in forum Qt Programming
    Replies: 4
    Last Post: 23rd February 2009, 17:42
  2. help in reading XML file
    By cshiva_in in forum Qt Programming
    Replies: 1
    Last Post: 24th March 2008, 13:55
  3. QTextStream loses position while reading file
    By bjh in forum Qt Programming
    Replies: 2
    Last Post: 13th February 2008, 15:47
  4. Replies: 3
    Last Post: 18th October 2007, 18:07
  5. QWT 5, QT3, SuSE 10.2. Crash and burn
    By DrMcCleod in forum Qwt
    Replies: 8
    Last Post: 7th September 2007, 20:53

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.