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. Pick-to: 6.6 6.5 Change-Id: Ib47a218989b4dcb5d51f648bc55bc02399bae602 Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io>
This commit is contained in:
parent
13fbedd162
commit
1fd1ffd03d
@ -455,13 +455,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…
Reference in New Issue
Block a user