[Solved] QDialog shuts down the whole application



  • Good day, colleagues!

    I want to write the authentication dialog before the main window start. So, I have this code:

    @QApplication app (argc, argv);

    Preferences_Getter getter (PREFERENCES_URL);
    Main_Window window;

    QObject::connect(&getter, SIGNAL (Finished(const QByteArray &)), &window, SLOT(show()));

    return app.exec();@

    Preferences_Getter is QObject with QNetworkAccessManager. Authenntication code is:

    @void Preferences_Getter::Authenticate (QNetworkReply * reply, QAuthenticator * authenticator) {

    QDialog dlg;
    ...
    if (dlg.exec() == QDialog::Accepted) {
    authenticator->setUser(ui.userEdit->text());
    authenticator->setPassword(ui.passwordEdit->text());
    }
    ...
    }@

    When I accept QDialog, my whole application shuts down. When I reject QDialog, main window starts normally.

    How can I fix it?



  • The point is the following:

    Afaik, the signal QApplication::lastWindowClosed is connected to QApplication::quit.
    As you have no other window than the dialog visible, it's the last window to close...

    When do you call Authenticate? inside the app.exec() I think?



  • Check out the QApplication::setQuitOnLastWindowClosed(bool) method.



  • Gerolf, Andre, thank you very much!

    QApplication::setQuitOnLastWindowClosed(bool) solved my problem!

    Authenticate of course is launched inside app.exec().



  • Hi usamytch,

    what might happen now, is that you close your main window and the app goes on running!
    Make sure, that you quit the app correctly then. Also if validation failes, call qApp->quit().



  • What you might do, is give your main window a signal that you can use to connect to the qApp->quit() slot. You might, for instance, reimplement the ::closeEvent() protected method, and emit your signal from there.



  • Thank you for advices, I've just called QApplication::setQuitOnLastWindowClosed(true) after successful authentication and run qApp->quit() in the other case.



  • Good solution as well, and simpler than mine! :-)


Log in to reply
 

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