can't close the Qdialog

  • hi, everyone.
    I have a class A which is a QDialog. in its constructor, it must read something from a file and if the file is not opened, the QDialog must be closed. I used


    but it doesn't work. what should I do???
    thank you very much

  • Moderators

    In the constructor the dialog is not even shown yet, so there's nothing to close.

    Usually with dialogs you have a code like this:

    SomeDialog dialog;
    dialog.exec();  //exec calls show() internally

    so if you want to prevent it from showing you can do something like this:

    SomeDialog dialog;
    if (dialog.isInitialized())

    where isInitialized() would return true or false depending on what the constructor did.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.