Unexpected return value from QMessageBox::exec()
Unsolved
General and Desktop
-
Hi All,
My platform: Linux kubuntu 14
QT Version: 4.7.1I generate a
QMessageBox
with two standard buttons as seen in the following code:QMessageBox msgBox; msgBox.addButton(tr(sn.c_str()), QMessageBox::NoRole); msgBox.addButton(tr(sn.c_str()), QMessageBox::YesRole); int ret = msgBox.exec(); switch (ret) { case QMessageBox::YesRole: { break; } case QMessageBox::NoRole: { break; } default: break; }
This code generates a qmessagebox with two buttons.
When I press the right buttonQMessageBox::NoRole
the return value fromexec()
is zero;
Even though the documentation states:
When using a QMessageBox with standard buttons, this functions returns a StandardButton value indicating the standard button that was clicked.
Any idea what I am doing wrong ?
Thanks
-
Since you don't call the QMessageButton with StandardButtons you have to use clickedButton() to determine the selected button.