Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C QT QT-Creator
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 14-Nov-11 22:04pm
Comments
SAKryukov at 15-Nov-11 3:07am
   
What's the problem?
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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. Smile | :)
 
—SA
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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!
  Permalink  
Comments
abhishekdurvasula at 15-Nov-11 23:33pm
   
thank you guys..
i got the solution...

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

  Print Answers RSS
0 OriginalGriff 240
1 Kamal Rocks 184
2 PIEBALDconsult 150
3 BillWoodruff 148
4 Jochen Arndt 135
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 15 Nov 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100