2

I have situation that I open QDialog window from the main.cpp file and then I wait for the exec() method to return based on success or fail of the QDialog. Like this :

   int main( ... ) {
    LoginDialog *loginDlg = new LoginDlg;

    if( loginDlg->exec() != Qt:;Accepted ) {
    return 0;
    }

    //check the login Info
    delete loginDlg;

    MainWindow w;
    w.show()
    return app.exec();
    }

From the Qt Examples (Address book) I saw I just can use the accept() and reject() slots. The thing is that I like the window to close based on some function flow, and not ok/close buttons. How can I trigger those slots from function? .

Angie Quijano
  • 4,167
  • 3
  • 25
  • 30
user63898
  • 29,839
  • 85
  • 272
  • 514

2 Answers2

6

As liaK pointed out you can just call the following functions from your code:

loginDlg->accept();
loginDlg->reject();

You can also call the following equivalent function using the result as a parameter:

loginDlg->done(QDialog::Accepted);
loginDlg->done(QDialog::Rejected);

PS: Note also there is no Qt::Accepted value as specified in your question. The correct constant is QDialog::Accepted

Fivos Vilanakis
  • 1,490
  • 12
  • 13
4

Just call them.. They are normal functions..

E.g:

loginDlg->accept();

Also see this..

Community
  • 1
  • 1
liaK
  • 11,422
  • 11
  • 48
  • 73