如何重置 QFile/QTextStream?
How to reset QFile/ QTextStream?
我正在获取一个文件,以便在第一次读取后重置。所有谷歌搜索都没有帮助。
如何在第一次读取文件后将其重置为开始?
试用一:
inFile = QFile( self._pathFileName )
inFile.open(QFile.ReadOnly | QFile.Text)
stream = QTextStream(inFile)
# Count first all lines in the file
self._numLinesRead = 0
self._mumLinesTotal = 0
while not stream.atEnd():
self._mumLinesTotal=+1
stream.readLine();
inFile.seek(0)
stream.seek(0)
pos = stream.pos() # pos is equal to 0 after this line verified with debugging
while( not stream.atEnd() ): # but here it still thinks he's at file end and jumps over
....
试验二:
inFile = QFile( self._pathFileName )
inFile.open(QFile.ReadOnly | QFile.Text)
stream = QTextStream(inFile)
# Count first all lines in the file
self._numLinesRead = 0
self._mumLinesTotal = 0
while not stream.atEnd():
self._mumLinesTotal=+1
stream.readLine();
inFile.close()
del inFile
del stream
inFile = QFile( self._pathFileName )
inFile.open(QFile.ReadOnly | QFile.Text)
stream = QTextStream(inFile)
# everyting has been reset?!
while( not stream.atEnd() ): # Nop it still thinks it is atEnd and jumps over
....
我尝试了网上找到的所有解决方案。没有任何帮助。我做错了什么?
不知道该说什么,但在系统完全重启后,“试用二”成功了。
第二次重启后(两天后更改了大量代码)“试用版”也出现了。
毕竟:从我的角度来看,这两个试验都是有效的。
如果您在开发和调试过程中发现奇怪的行为,请尝试重新启动。
我正在获取一个文件,以便在第一次读取后重置。所有谷歌搜索都没有帮助。
如何在第一次读取文件后将其重置为开始?
试用一:
inFile = QFile( self._pathFileName )
inFile.open(QFile.ReadOnly | QFile.Text)
stream = QTextStream(inFile)
# Count first all lines in the file
self._numLinesRead = 0
self._mumLinesTotal = 0
while not stream.atEnd():
self._mumLinesTotal=+1
stream.readLine();
inFile.seek(0)
stream.seek(0)
pos = stream.pos() # pos is equal to 0 after this line verified with debugging
while( not stream.atEnd() ): # but here it still thinks he's at file end and jumps over
....
试验二:
inFile = QFile( self._pathFileName )
inFile.open(QFile.ReadOnly | QFile.Text)
stream = QTextStream(inFile)
# Count first all lines in the file
self._numLinesRead = 0
self._mumLinesTotal = 0
while not stream.atEnd():
self._mumLinesTotal=+1
stream.readLine();
inFile.close()
del inFile
del stream
inFile = QFile( self._pathFileName )
inFile.open(QFile.ReadOnly | QFile.Text)
stream = QTextStream(inFile)
# everyting has been reset?!
while( not stream.atEnd() ): # Nop it still thinks it is atEnd and jumps over
....
我尝试了网上找到的所有解决方案。没有任何帮助。我做错了什么?
不知道该说什么,但在系统完全重启后,“试用二”成功了。
第二次重启后(两天后更改了大量代码)“试用版”也出现了。
毕竟:从我的角度来看,这两个试验都是有效的。
如果您在开发和调试过程中发现奇怪的行为,请尝试重新启动。