从Qt中的文件读取 [英] Reading from a file in Qt
本文介绍了从Qt中的文件读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
该文件大约有2000行.
我只希望一次显示100行.
我按下了下一个按钮.
单击该按钮时,必须显示100行.
我无法前进.
请帮忙.
在此先感谢
解决方案
在此处使用readLine
的基本代码示例: ^ ].
在这种情况下,应保持打开文件的状态.每次请求转发页面时,请阅读100行.
不幸的是,向后滚动视图会更加困难,因为所有赞"的长度可能会有所不同,因此在阅读之前的所有行之前,您不知道每一行的文件位置.首次读取时,您需要动态按100行块索引文件,并将结果保留在按块索引索引的文件位置的哈希表中.这很简单,但是在实现过程中需要一些思考. :-)
—SA
您必须使用以下方法创建一个从QFile继承的类:-OpenFile()-ReadNextHundred()-CloseFile().
然后将ReadNextHundred()连接到按钮"Next" Clicked Event.
单击一次按钮后,应清除显示"小部件并显示下一行.
我认为此链接中的示例将为您提供帮助:
http: //www.qtforum.org/article/34254/how-to-read-a-textfile-and-display-result-in-gui-qt-programming-problem.html [ 解决方案
Look at the basic code samples here wherereadLine
is used: http://lists.trolltech.com/qt-interest/2002-03/msg00576.html[^].
In your case, you should keep the file opened. Read 100 lines each time you request to forward a page.
Unfortunately, scrolling your view back would be more difficult, because all likes can have different length, so you don''t know file position of each line before you read all previous lines. You would need to index your file by 100-line chunks on the fly on first read, keeping the results in a hash table of file positions indexed by chunk indexes. It is fairly simple but will require some thinking during implementation. :-)
—SA
Hi,
You must create a class that inherits from QFile with methods : - OpenFile() - ReadNextHundred() - CloseFile().
Then you connect ReadNextHundred() to the button "Next" Clicked Event.
Once button Clicked you should clear Display widget and show next lines.
I think that the example in this link would help you :
http://www.qtforum.org/article/34254/how-to-read-a-textfile-and-display-result-in-gui-qt-programming-problem.html[^]
Regards!
这篇关于从Qt中的文件读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文