0

I have following code

1) File dialog.h

class Dialog : public QDialog
{
Q_OBJECT

public:
    Dialog(QWidget *parent = 0);

private slots:
    void questionMessage();
};

Case1:

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";
  }

The issue is when I click on X mark at the top right then the QMessagebox does not get closed

Case2:

but If I have following code

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";
  }

If I put QMessageBox::Cancel then it is working fine . It will be helpful if someone can guide me why I am not able to close QMessageBox with X in Case1

demonplus
  • 5,613
  • 12
  • 49
  • 68
TechEnthusiast
  • 273
  • 4
  • 18

0 Answers0