Multithreading and QProgressBar
-
Hello there !
I am begginer in Qt and I try to devellop an application that use a thread to load a specific file. To do that, I've created a custom thread by inheriting QThread class, and put a signal in this class to send the loading value. This signal is connected to a slot in my mainwindow that set the value of a QProgressBar located in the statusBar area.
So far, everything works fine.
But now I would like to have the possibility to open severals files at the same time, and to display the global processing progression in my progressbar. How shall I do to handle all the threads loading progression signals and to connect them to my slot to set the global progress bar value ?
Thanks for your help !
-
Hi,
One way is to first gather the step counts (or whatever reference value you have) for all the files that you are going to load and sum them so you can just increment the progress bar.
Otherwise you can also have one progress bar per file.
-
@SGaist thanks for your reply.
I was thinking about something like this but how do you gather the step counts ? Because to sum them, you have to know from which thread the signal is emited ?
If for example you have :
int globalProgression = thread1Progression + thread2Progression + ... progressBar->setValue(globalProgression);
How do you increment all the threadProgression individualy ?
-
First thing first: how do you know how many steps each of your thread has ?
-
@BobDon one solution would be as follows.
1)get the count of files that is being opened simultaneously.
2)If say 6 files are opened, you can set step count as 6*100 = 600
3)Each processing thread should check filesize and report the delta processed in percentage wise.
4)Accumulate the percentage progress reported from each thread
and update the value in Progressbar