Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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.

    0_1531832045169_896284bd-fae0-4e74-8f49-7692cf75f45c-image.png

    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.

    0_1531832699365_f1d6ad41-f8c7-495f-944a-df52eeba1598-image.png

    Is this a bug or my bad coding?

    -Scott


  • Moderators

    @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.


Log in to reply