david
david

Reputation: 139

QProgressDialog not drawing during pause

I have cause to use a QProgressDialog in a loop, and I'd like the dialog to pop up and wait for user input before showing the dialog. However, the second time through the loop, the dialog remains faceless until after it starts updating proper. Here is some example code:

QProgressDialog progressDialog("progress", "Cancel",
               0, 10000);
progressDialog.setMinimumDuration(0);
progressDialog.setWindowModality(Qt::WindowModal);

while(1) {

  progressDialog.show();
  progressDialog.setValue(0);

  qApp->processEvents();

  getchar();

  for(unsigned int i = 0; i < 10000; i++)
    progressDialog.setValue(i+1);
}

The first time it displays all the widgets in the dialog, but the second time through, nothing. The same thing happens if I move the QProgressDialog declaration inside the loop. How can I get it to show all the widgets while waiting for user input every time through the loop, and why doesn't it do that in the code above?

Upvotes: 1

Views: 1048

Answers (1)

This is because you do all the work in GUI thread. As getchar() does not return until user enters something GUI thread is unable to repaint widgets and windows.

You need to:

Upvotes: 1

Related Questions