[Qt-interest] QTextStrem.pos() incredible slow

Niklaus Hersche niklaus.hersche at gesys.ch
Thu Oct 28 14:54:45 CEST 2010


Hi

I scan a tag in a utf16 text file with QTextStrem.readLine().
Once I have found the tag, I'd like to keep the file position in memory for
further use.

Unfortunately QTextStrem.pos() is so slow, that it's almost of useless.

To find the tag it takes 281 ms.
The subsequent call of QTextStrem.pos() takes 14078 ms.

This is incredible, isn't it?

To me this looks like a bug. Has this issue been fixed in a later version,
or am I doing something  wrong?

Has anybody a clue?

Thanks
Nik



- QTextStrem.pos() returns: 6037728
- OS: WinXP
- Qt: 4.5.2

Simple code to reproduce the issue:
//-----------------------------------------------------------------------
bool test(){

	qint64 filePos = -1;
	QFile f(c_ProjectFile);
	QTextStream ts(&f);

	if(!f.open( QFile::ReadOnly | QFile::Text)){
		return false;
	}

	ts.setCodec("UTF-16LE");

	QTime tm1;
	tm1.start();

	for(QString line; !(line = ts.readLine()).isNull(); ){

		if(line.startsWith( c_StartTag, Qt::CaseInsensitive)){
			int elapsed = tm1.elapsed();
			qDebug() << "search: " << elapsed << " ms";

			tm1.restart();
			filePos = ts.pos();
			elapsed = tm1.elapsed();
			qDebug() << "pos: " << elapsed << " ms";
			return true;
		}

	} // for

	return false;
}
//-----------------------------------------------------------------------









More information about the Qt-interest-old mailing list