首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何重置QFile/ QTextStream?

如何重置QFile/ QTextStream?
EN

Stack Overflow用户
提问于 2021-08-24 16:02:58
回答 1查看 40关注 0票数 0

我正在获取一个文件,以便在第一次读取后重置。所有的谷歌搜索都没有任何帮助。

如何在第一次读取文件后将其重置为begin?

试验一:

代码语言:javascript
复制
        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
            ....

试验二:

代码语言:javascript
复制
        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
            ....

我尝试了在网上找到的所有解决方案。什么都没有用。我哪里做错了?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-08-26 05:23:01

不知道我应该说什么,但在系统完全重启后,“试用二”起作用了。

在第二次重启之后(两天后进行了大量代码更改),“试用版一”也恢复了活力。

毕竟:从我的角度来看,这两个试验都是有效和有效的。

如果您在开发和调试过程中发现奇怪的行为,请尝试重新启动。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68910589

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档