从Qt中的文件读取 [英] Reading from a file in Qt

查看:139
本文介绍了从Qt中的文件读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我想在qt中读取文件.
该文件大约有2000行.
我只希望一次显示100行.
我按下了下一个按钮.
单击该按钮时,必须显示100行.
我无法前进.
请帮忙.
在此先感谢

解决方案

在此处使用readLine的基本代码示例:
—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 where readLine 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆