Solved progress bar not updating during iterations but updating once the process is completed?
-
Only one thing: You must not access or try to modify widgets outside the main gui thread. So fix your code and use proper signals/slots instead.
-
@Christian-Ehrlicher You mean since i am updating my progress bar with iteration number inside calib function(which is running in another thread) so my progress bar update is not working as intended right? . Even If i run my calib function in the same thread it is giving me same kind of output!
I didnt change anything in SIGNAL and SLOT implementation. (It was the same as mentioned in one of the screenshots above.)
Please correct me if i am wrong!.
-
When you run your loop in the gui thread then the ui is blocked since you block the eventloop.
-
This post is deleted! -
Move your heavy calculation into an own thread as shown in the documentation and the examples there.
-
@Christian-Ehrlicher Hi!, I didnt change anything in the code as mentioned in the question. This comment is rather to get some more clarity for myself. I think i moved my heavy calculation part into the different thread. But inside this new thread i have two for loops and inside my second loop i want to pass iteration number by normalizing it to 0-100 to progressbar. So I am still confused why it is happening like this. And as per what i found is Threads can run an event loop.
Sorry for being dumb :-( . The more i go to documenation and some questions in stack and qt forum it is making me more confuse :-). May be because i am beginner :-)
-
@aravmadd said in progress bar not updating during iterations but updating once the process is completed?:
So I am still confused why it is happening like this
Because you modify ui stuff from another thread which is not allowed. Use signals and slots as I already wrote 3 days ago.
-
@Christian-Ehrlicher Hi Thanks I am working on implementing it in worker class. I am trying to create worker class and do some intensive work there.
I have a small question here , how can i get information from ui into worker class? For example if i have some text in LineEdit i need to get this information in worker class.
-
@aravmadd said in progress bar not updating during iterations but updating once the process is completed?:
how can i get information from ui into worker class?
via signals/slots
-
@jsulm Thanks it took me some time to figure it out on correct implementation of signals and slots.
Now its working.
What i did was
I ran the heavy calculation function in another thread using QtConcurrent.
Then from the heavy function i emitted signal , with the emitted signal i defined one slot(in my widget.cpp) which updates my progress bar.
Here is how it looksconnect(this, &Widget::updateProgress, this, &Widget::onProgressValueChanged);
After this i connected signal and slot properly it worked fine.
Initially i thought it is not working because the update is too fast that i cannot see real update in progress bar, then i only updated at 25 percent and 50 percent and 75 and 100 percent to my progress bar. Then i can see the progress in progress bar.