Unexplained delay after QProgressBar finish loading
-
Hi all,
I have emit signal from a loop (which make some calculations) that triggers progress bar update which located on the main GUI, after the loop ends the progress bar updated to 100% (the progress bar become hidden when the process ends), but than there is a delay, the progress bar stays on 100% and sometimes the mouse changes to busy, and only after few seconds the progress bar become hidden (indicates me that the delay ends), there is nothing after that loop, so nothing I can thinks of can make this delay.
- I should note that if the loop calculations are light (meaning not a lots of calculations need to be done) there is no such delay.
The emit signal is inside a class in the logic layer, I have try something by including
<QtGui/QApplication>
into that class (which sounds to me not the right thing to do, as this is the logic layer so why it should need QtGui libraries, but I'm only testing something), I put the following codeqApp->processEvents();
inside the loop and now things seems to run smother, no busy mouse, but still there is a delay (the only thing different I can react with the GUI while this delay occurs, but there is no updated results until this delay ends).Because of the test with the
processEvents()
I was thinking it's something related to threads, but if so how can I correct the delay behavior, of-course if anyone thinks it could be something else, please do tell.Some sample code:
Logic layer class:
@#include <QtGui/QApplication>
...processMethod(...) { Loop(...) { qApp->processEvents(); emit processBarSignle(value); ...some calculations... } emit processBarSignle(100); }@
View layer (MainWindow):
@ on_btn_nextProcess_clicked()
{
m_ui->pBar_process->setVisible(true);
LogicClass->processMethod(...);
m_ui->pBar_process->setVisible(false);
}@Thanks
-
You emit the signal before the calculation occurs. Loop has to go the whole cycle before it will update the progress bar with processEvents(). Maybe that is the cause.
-
The delay was before I used processEvents().
But nevertheless, you mean to do something like this:@processMethod(...)
{
Loop(...)
{
...some calculations...
qApp->processEvents();
emit processBarSignle(value);
}
emit processBarSignle(100);
}@or this
@processMethod(...)
{
Loop(...)
{
qApp->processEvents();
...some calculations...
emit processBarSignle(value);
}
emit processBarSignle(100);
}@?
-
@
processMethod(...)
{
Loop(...)
{
...some calculations...
emit processBarSignle(value);
qApp->processEvents();
}
emit processBarSignle(100);
}
@Not sure that will change anything in your case, but it has some potential :)
-
You was right it didn't worked, but was worth to try :P