简体   繁体   中英

Qt dialog how can I trigger accept() and reject() from function

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? .

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

Just call them.. They are normal functions..

Eg:

loginDlg->accept();

Also see this ..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM