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

Calling QTextStream::reset() causes QTextStream to read lines of text on invalid file positions

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Out of scope
    • Icon: P3: Somewhat important P3: Somewhat important
    • Some future release
    • 4.3.4
    • Core: I/O
    • None

      Calling QTextStream::reset() causes QTextStream to read lines of text on invalid file positions:

      Example to reproduce:

      #include <QtCore>
      int main( int argc, char **arhv)
      {
      QCoreApplication app(argc, arhv );
      QTextStream readerTextStream;

      QFile readerInputFile("test.txt");
      readerInputFile.open( QIODevice::ReadOnly | QIODevice::Text );
      readerTextStream.setDevice(&readerInputFile);
      qDebug() << "READ :" << readerTextStream.readLine();
      readerInputFile.close();

      qDebug()<<"new file is about to open";
      QFile file ("test.txt");
      file.open(QIODevice::ReadOnly | QIODevice::Text);
      readerTextStream.reset(); // not needed docs say that reset is done by set device.
      readerTextStream.setDevice(&file);

      while(! readerTextStream.atEnd())
      qDebug() << "READ :" << readerTextStream.readLine();

      file.close();
      return app.exec();
      }

      Update: The following patch fixes this problem. As the docs say, this function does not affect the buffered data at all, but it's reasonable to assume that data that has already been read is removed from the buffer when the stream is reset.

      — qtextstream.cpp 2008/01/17 12:55:21.000000000
      +++ qtextstream.cpp 2008/01/22 12:51:47.000000000
      @@ -453,7 +453,10 @@
      stringOffset = 0;
      stringOpenMode = QIODevice::NotOpen;

      • readBufferOffset = 0;
        + if (readBufferOffset > 0) { + readBuffer.remove(0, readBufferOffset); + readBufferOffset = 0; + }

        readBufferStartDevicePos = 0;
        lastTokenSize = 0;

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

            stormols Marius Storm-Olsen
            admin Administrator
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes