开发者

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

E.g:

loginDlg->accept();

Also see this..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜