[SOLVED]Reading and updating progress bar
-
i'm reading a very big text file and for each line i call a parser function , basically the "reading" of the file takes up a considerable amount of time .
i want to attach a progress bar that shows how much i have read so far , meaning if there is way to get total number of lines plus i can define a counter for each line i read then the percent would be (count/total number of lines) .can it be done ?
-
Yes. This can be done. While reading the file continuously you need to keep processing the events to ensure that UI is updated. i.e call processEvents(..). If not use threads to process the file and update the UI using signal and slot or events.
-
[quote author="Dheerendra" date="1409842241"]Yes. This can be done. While reading the file continuously you need to keep processing the events to ensure that UI is updated. i.e call processEvents(..). If not use threads to process the file and update the UI using signal and slot or events.[/quote]
maybe my question wasn't clear , sorry , i meant how to get total number of lines a file contains ?
-
You need to count manually. There is no direct one shot api. U can do it based on the size than lines.
-
Can you pls explain how to do it by size ?
-
Here you can use "QFileInfo":http://qt-project.org/doc/qt-5/qfileinfo.html#size
this will give you that file size then according to the size that you are reading you can implement a progress bar that will be updated with a signal and slot mechanism fount in Qt -
Thank you sir
-
if that solve your problem please edit your first post title and add [SOLVED] in order for others to know that is solved