standarddialogs: Don't assume QMessageBox::exec() returns clicked role
When adding custom buttons to a QMessageBox the return value of exec() as well as result() is not a StandardButton value, but instead an opaque value, and the documentation says to use clickedButton() to determine which button was clicked. Change-Id: Ib47a218989b4dcb5d51f648bc55bc02399bae602 Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io> (cherry picked from commit 1fd1ffd03d6889273f574c698e07c611bd311fd9) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit a431a6002311bcfb9ef806ae101cb27e96c26722)
This commit is contained in:
parent
1977b778f0
commit
4c39b0d619
@ -454,13 +454,15 @@ void Dialog::warningMessage()
|
||||
tr("Delete the only copy of your movie manuscript?"), { }, this);
|
||||
msgBox.setInformativeText(tr("You've been working on this manuscript for 738 days now. Hang in there!"));
|
||||
msgBox.setDetailedText("\"A long time ago in a galaxy far, far away....\"");
|
||||
msgBox.addButton(tr("&Keep"), QMessageBox::AcceptRole);
|
||||
msgBox.addButton(tr("Delete"), QMessageBox::DestructiveRole);
|
||||
if (msgBox.exec() == QMessageBox::AcceptRole)
|
||||
auto *keepButton = msgBox.addButton(tr("&Keep"), QMessageBox::AcceptRole);
|
||||
auto *deleteButton = msgBox.addButton(tr("Delete"), QMessageBox::DestructiveRole);
|
||||
msgBox.exec();
|
||||
if (msgBox.clickedButton() == keepButton)
|
||||
warningLabel->setText(tr("Keep"));
|
||||
else
|
||||
else if (msgBox.clickedButton() == deleteButton)
|
||||
warningLabel->setText(tr("Delete"));
|
||||
|
||||
else
|
||||
warningLabel->setText("");
|
||||
}
|
||||
|
||||
void Dialog::errorMessage()
|
||||
|
Loading…
x
Reference in New Issue
Block a user