The dialog box determines if the ' Confirm key ' or ' Cancel key ' is pressed

Source: Internet
Author: User

1. Using the EXEC () return value

It is necessary to distinguish whether the user presses "OK" or "Cancel". The dialog box can be closed by calling the accept () or reject () slot, and EXEC () returns the appropriate accepted or rejected.


1. Example 1

//按下的是Cancel键if(fileDialog->exec()==QFileDialog::Rejected) {      qDebug("取消"//按下的是OK键elseif(fileDialog->exec()==QFileDialog::Accepted) {      qDebug("确认"); }

However, this "confirm key" needs to be pressed two consecutive times to receive, should be called two times exec () reason.


2. Example 2

and changed it to this:

    if(fileDialog->exec()==QFileDialog::Accepted)    {        qDebug("OK");    }    else    {        qDebug("Cancel");    }
2. Using signal accepted () and rejected ()
//okconnect(fileDialog,SIGNAL(accepted()),this,SLOT(close()));//Cancel connect(fileDialog,SIGNAL(rejected()),this,SLOT(close()));

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The dialog box determines if the ' Confirm key ' or ' Cancel key ' is pressed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.