Details
-
Bug
-
Resolution: Out of scope
-
P3: Somewhat important
-
4.3.4
-
None
Description
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;