Andrea Fiore
Andrea Fiore

Reputation: 71

Progress bar change the value but not update the graphic

I try much method i have find to do this, but no one work for me.

I have tried with qApp.processEvents() and with update() but no one work.

void GUI::startLoading(int currentFile) {
    ui->progressBar->setValue(currentFile);
    ui->progressBar->update();
}

currentFile is an int of the current loaded file from another function.

debug and build result

Here's a screenshot of de dubug that told the current value of the progress bar, but the progress bar don't increment.

Upvotes: 0

Views: 1788

Answers (1)

ypnos
ypnos

Reputation: 52357

Are you doing busy work in the GUI thread? Qt needs to get a chance to process events for the redraw to happen.

update() only enqueues the redraw. Note that setValue() calls update() itself. To avoid this problem, you can call QEventLoop::processEvents() from time to time (e.g. at the same place where you update the progress bar), or use a worker thread.

Upvotes: 0

Related Questions