Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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 !


  • Lifetime Qt Champion

    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 ?


  • Lifetime Qt Champion

    First thing first: how do you know how many steps each of your thread has ?


Log in to reply