Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [Solved] QDialog shuts down the whole application

    General and Desktop
    3
    8
    4190
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • U
      usamytch last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • G
        giesbert last edited by

        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?

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply Reply Quote 0
        • A
          andre last edited by

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

          1 Reply Last reply Reply Quote 0
          • U
            usamytch last edited by

            Gerolf, Andre, thank you very much!

            QApplication::setQuitOnLastWindowClosed(bool) solved my problem!

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

            1 Reply Last reply Reply Quote 0
            • G
              giesbert last edited by

              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().

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              1 Reply Last reply Reply Quote 0
              • A
                andre last edited by

                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.

                1 Reply Last reply Reply Quote 0
                • U
                  usamytch last edited by

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

                  1 Reply Last reply Reply Quote 0
                  • A
                    andre last edited by

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

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post