标签:accepted rejected accepted rejected
需要分清用户按下“OK”还是“Cancel”。对话框可以通过调用accept()或reject()槽来被关闭,并且exec()将返回适当的Accepted或Rejected。
1. 例1
 //按下的是Cancel键
 if(fileDialog->exec()==QFileDialog::Rejected)
 {
      qDebug("取消");
 }
 //按下的是OK键
 else if(fileDialog->exec()==QFileDialog::Accepted)
 {
      qDebug("确认");
 }
但是这样“确认键”需要连续按下两次才能接收到,应该是调用了两次exec()的原因。
2. 例2
然后改成了这样:
    if(fileDialog->exec()==QFileDialog::Accepted)
    {
        qDebug("OK");
    }
    else
    {
        qDebug("Cancel");
    }
//ok
 connect(fileDialog,SIGNAL(accepted()),this,SLOT(close()));
//Cancel 
 connect(fileDialog,SIGNAL(rejected()),this,SLOT(close()));
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:accepted rejected accepted rejected
原文地址:http://blog.csdn.net/lyh__521/article/details/47111125