This is what I have:
void MyThread::run() {
int progress = 0;
while (1) {
// do something
progres++;
emit(progressChanged(progress));
}
}
// mainwindow
auto t = new MyTread();
connect(t, SIGNAL(progressChanged(int)), this, SLOT(onProgressChanged(int)));
t->start();
void MaiWindow::onProgressChanged(int) {
this->progressBar->setValue(progressBar->value() + 1);
}
It works, the job in the thread gets done, and the progress bar goes all the way up to 100%.
But the UI is completely frozen/laggy. Dragging a window with the progress bar results in a 5 second delay. I tried using lower thread priorities - no result.
Maybe I need a mutex here?