Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
hi i want to read a file in qt.
the file has around 2000 lines.
i want only 100 lines to be displayed at once.
i have put a next button.
on clicking this button next 100 lines must be displayed.
i am unable to go forward.
please help.
thanks in advance
Posted
Comments
Sergey Alexandrovich Kryukov 15-Nov-11 3:07am    
What's the problem?
--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!
 
Share this answer
 
Comments
Abhishek Durvasula 15-Nov-11 23:33pm    
thank you guys..
i got the solution...
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900