What is the proper way to set QProgressBar to update from the logic layer? [Solved]
-
If I want to update a QProgressBar on the view layers from a loop on the logic layer (such as each iteration will update the progress bar), what is the proper way to do that?
Thanks
-
@
forever { // or any other loop you have
// do your calculations
qProgressBar->setValue(currentVal);
qApp->processEvents();
}
@"::setValue()":http://qt-project.org/doc/qt-4.8/qprogressbar.html#value-prop
Alternatively, you can emit some signal from your logic, and connect to it in your GUI.
-
The first solution you suggested, requires me to send as parameter the progress bar from the view layer to the logic layer?
The second suggestion requires me to emit signal in each iteration?
Thanks
-
Yes. Now you mention it, I can see it might not be exactly what you want.
Yes and no. You have to emit the signal to update the progress bar, but you don't have to do it every time if you don't want to.
-
... or you can add timer and update progress bar value on timeout event via signal or setValue(value)...