Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-9814

Calling QTextStream::pos while reading a file with readLine() results in unknown errors

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 4.8.0
    • 4.7.0
    • Core: I/O
    • None
    • Ubuntu 9.10 32bit. Also tested on WinXP 32bit.
    • 17a4f332f0d416af842145f0ebc7f2ebe7f33527

    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

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            goffart Olivier Goffart (closed Nokia identity) (Inactive)
            holmsted Lasse Holmstedt
            Votes:
            4 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes