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]Login dialog and problem with quit app
QtWS25 Last Chance

[Solved]Login dialog and problem with quit app

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 5.4k 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.
  • H Offline
    H Offline
    Hostel
    wrote on last edited by
    #1

    I have a problem with closing properly an application. 8 months ago I found a web with solution, but now that url is broken and I need yours help. I remember that problem is in application event loop, because when dialog is analised and closed then an event loop is not running yet. Here is my code - what should I add to resolve this issue?
    @
    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);

    LogInDialog logInDialog; // QDialog class
    
    logInDialog.exec();
    int dialogResult = logInDialog.result();
    if( dialogResult == QDialog::Accepted )
    {
        MainWindow w;
        w.show();
    }
    // if a dialogResult is not equal QDialog::Accepted then I want to close app, but now an application is running
    return a.exec();
    

    }
    @

    1 Reply Last reply
    0
    • BilbonSacquetB Offline
      BilbonSacquetB Offline
      BilbonSacquet
      wrote on last edited by
      #2

      I don't know exactly what is your challenge here, but you don't need to start the application message loop:

      @
      if (dialogResult != QDialog::Accepted)
      return -1;

      MainWindow w;
      w.show();

      return a.exec();
      @

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rokemoon
        wrote on last edited by
        #3

        Also you can write like this:
        @
        LogInDialog logInDialog; // QDialog class

        if (logInDialog.exec() != QDialog::Accepted)
        return -1;

        MainWindow w;
        w.show();

        return a.exec();
        @
        So as I understand you have two buttons in your dialog (Ok & Cancel),
        if you want that dialog return you QDialog::Accepted or QDialog::Rejected
        you need to connect your buttons to dialog's slots "accept":http://doc.qt.nokia.com/latest/qdialog.html#accept and "reject":http://doc.qt.nokia.com/latest/qdialog.html#reject
        Example:
        @
        class TestDialog: public QDialog
        {
        public:
        TestDialog()
        {
        QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
        | QDialogButtonBox::Cancel);

         connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
         connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
         QVBoxLayout *layout = new QVBoxLayout();
         layout->addWidget(buttonBox);
         setLayout(layout);
        

        }
        };
        @
        and main
        @
        int main(int argc, char *argv[])
        {
        QApplication a(argc, argv);

        TestDialog dlg;
        if (dlg.exec() != QDialog::Accepted)
          return -1;
        Widget w;
        w.show();
        
        return a.exec();
        

        }
        @
        All works fine.

        1 Reply Last reply
        0
        • H Offline
          H Offline
          Hostel
          wrote on last edited by
          #4

          Thanks for reply. Unnecessery I was looking for complicated solution - in many cases, the simple solution is the best solution.

          1 Reply Last reply
          0
          • R Offline
            R Offline
            rokemoon
            wrote on last edited by
            #5

            [quote author="Hostel" date="1321433146"]in many cases, the simple solution is the best solution.[/quote]
            Yep you are right

            1 Reply Last reply
            0
            • H Offline
              H Offline
              Hostel
              wrote on last edited by
              #6

              I tested a solution and I have a conclusion:

              This is wrong:
              @
              return 0;
              @
              In Qt Creator I have a message that application was unexpected closed.

              This is good:
              @
              exit( 0 );
              @

              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