PDA

View Full Version : Progress of reading the file



ModeZt
11th April 2009, 14:38
I read the input text file line by line.


dataFile = new QFile(fileName);
dataFile->open(QIODevice::ReadOnly | QIODevice::Text);
dataStream = new QTextStream(dataFile);
while( !dataStream->atEnd() ) {
line = dataStream->readLine();
...
}

The file is > 200Mb.
I need to update a progress bar while i analize the lines.
I was going to use

100 * currentLine / numberOfLines
but how do i get the number of lines in the file?..

Thx!

wysota
11th April 2009, 23:36
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.