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