Details
Description
See test case below. The file being used is "qtcreator.qdoc", from qtcreator/doc/: http://qt.gitorious.org/qt-creator/qt-creator/blobs/master/doc/qtcreator.qdoc
The issue does not seem to happen with very small files, but with anything in the megabyte range (and even hundreds of kB's).
The example will work if pos() is not called inside a loop, so that's the likely culprit.
#include <QtCore/QCoreApplication> #include <QFile> #include <QTextStream> #include <QDebug> void parseFile(); int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); parseFile(); return a.exec(); } void parseFile() { QFile f("qtcreator.qdoc"); f.open(QIODevice::ReadOnly); QTextStream s(&f); QList<qint64> rowPositions; while(!s.atEnd()) { qint64 pos = s.pos(); if (pos == -1) { qDebug() << "Error occurred, " << s.atEnd() << rowPositions.last() << ", size:" << s.device()->size(); break; } rowPositions.append(pos); s.readLine(); } qDebug() << "error string:" << s.device()->errorString() << s.status(); }
—
Error message:
Error occurred, false 131679 , size: 202305
error string: "Unknown error" 0