我有以下代码
1)文件dialog.h
class Dialog : public QDialog
{
Q_OBJECT
public:
Dialog(QWidget *parent = 0);
private slots:
void questionMessage();
};
情况1:
2)dialog.cpp
void Dialog::questionMessage()
{
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, tr("QMessageBox::question()"),
MESSAGE,
QMessageBox::Yes | QMessageBox::No );
if (reply == QMessageBox::Yes)
qDebug() << "Yes";
else if (reply == QMessageBox::No)
qDebug() << "No";
else
qDebug() << "Cancel";
}
问题是当我点击右上角的X标记然后QMessagebox没有关闭时
情况2:
但如果我有以下代码
void Dialog::questionMessage()
{
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, tr("QMessageBox::question()"),
"MESSAGE",
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
if (reply == QMessageBox::Yes)
qDebug() << "Yes";
else if (reply == QMessageBox::No)
qDebug() << "No";
else
qDebug() << "Cancel";
}
如果我把QMessageBox :: Cancel那么它工作正常。如果有人可以指导我为什么我无法在Case1中使用X关闭QMessageBox将会很有帮助