Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] QDialog shuts down the whole application

[Solved] QDialog shuts down the whole application

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 4.5k Views
  • 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 Offline
    U Offline
    usamytch
    wrote on last edited by
    #1

    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
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      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
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • U Offline
          U Offline
          usamytch
          wrote on last edited by
          #4

          Gerolf, Andre, thank you very much!

          QApplication::setQuitOnLastWindowClosed(bool) solved my problem!

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

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on last edited by
            #5

            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
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              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
              0
              • U Offline
                U Offline
                usamytch
                wrote on last edited by
                #7

                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
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #8

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

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved