QDialog bug?
-
Okay, I have a QDialog that I call just before a while statement:
QProgressDialog progress("Loading Log Data...","Cancel", 0, 0, this); progress.setWindowModality(Qt::NonModal); progress.show();
When I say 'progress.show()' the dialog pops up as a blank dialog box, but it will act as expected, going away when the while statement completes.
But when I say 'progress.exec() it shows the 'busy' bar as I want (because it's unknown how large the data set is that the while statement is working on), but it never allows the while statement to start until I cancel the dialog - then the dialog goes away and then the 'while' statement starts and completes.
Is this a bug or my bad coding?
-Scott
-
@MScottM said in QDialog bug?:
Is this a bug or my bad coding?
rather bad coding.
If you do your heavy work (while-loop) in the gui thread nothing can update the display obviously.
So you should move your while loop into another thread and report the progress to the dialog via signals.Alternatively (which i actually never recommend) you can call QCoreApplication::processEvents() in the while loop to let the gui thread do it's work intermediately.
btw. QDialog::exec() creates it's own event-loop and blocks until the dialog is closed.
-
@raven-worx - thanks for your reply. It makes sense - I'll make understanding worker threads my next project.