[Kst] QTextStream::readLine() vs QFile::ReadBlock() vs QFile::ReadLine()

George Staikos staikos at kde.org
Fri Jan 14 19:47:16 CET 2005


On Friday 14 January 2005 13:32, Brisset, Nicolas wrote:
> I am trying to add configuration options to the ASCII datasource, which
> leads to quite a lot of changes to account for all the new options. Some
> of the changes regard how we read/parse the data file. As I'm not a
> specialist I must confess I wonder what the differences are between the
> 3 methods QTextStream::readLine(), QFile::ReadBlock() and
> QFile::ReadLine(). Of course, I understand the differences wrt to how to
> use them, but it's not clear to me what their relative performance is.

   QFile::readBlock() will give you the best performance, and probably 
QFile::readLine() next.  readBlock() should map very close to a system call.

> Could someone help me understand why there are so many lines in
> ascii.cpp (readField() method) to just detect where the new data lines
> start when it would be much easier to e.g. just use a QTextStream to
> read the file line by line and discard lines beginning with one of the
> comment delimiters ?

   It builds an index for fast seeking to a given line.

> Another question I have is whether there are other ways of reading
> directly from a given point in the file other than QFile::at() (e.g.
> with a QTextStream) ?

  You can use QFile::at() and then attach a QTextStream to the QFile I think.  
Or perhaps attach first, then use at(), then read from the text stream.  One 
of those two should work.

-- 
George Staikos
KDE Developer				http://www.kde.org/
Staikos Computing Services Inc.		http://www.staikos.net/


More information about the Kst mailing list