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

[SOLVED]QDialog problem, how i can keep the QDialog show until some case matches?



  • i write a dialog, which let the user enter a fileName, i want to keep the dialog show Until user enter a fileName which does Not exist.
    i write like this in the func:
    QDialog dlg(this);
    dlg.exec();
    if (dlg.result() == QDialog::Accepted)
    {
    ...
    while (QFile::exists(newFileName))
    {
    dlg.exec();
    }
    ....
    }
    but i found it's wrong. what should i do this work?
    thank you!


  • Moderators

    I would not wait for the dialog to be closed. You should reimplement QDialog class and handle the OK button yourself: when a file exists, you should reject the result. If it does not, you can set the Accepted state.



  • yeh, i inherit from QDialog, and reimplement the accept.
    but u know, it's easy and convient to do this Check in the window's slot, But not the custom QDilaog, because the relative path is in the window, and i don't want to pass these related param to the QDialog.
    thank you


  • Moderators

    Sorry, I don't understand your resoning. How is it possible for the dialog (where the user selects the path and file name) not to know the file name?


Log in to reply