From a87fbaa5de858e80e5e8315e7cf9726dcd3ef122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Bri=C3=A8re?= Date: Thu, 1 Sep 2022 16:55:04 -0400 Subject: [PATCH] qt5+: Pass single `StandardButtons` arg. to `QMessageBox` funcs [4/4] Invoking `QMessageBox` functions with separate `button0`, `button1`, ... arguments was deprecated in Qt 4; all button specifications are now passed within a single `QMessageBox::StandardButtons` argument. This commit takes care of the last such instance, where buttons were passed this time as `QString`. This requires calling `addButton()` for each one, as well as replacing the following `switch` with an `if`, since the return type of `clickedButton()` is a (non-constant) pointer. (For the record, since we are using custom buttons, the return value of `exec()` is now an opaque value.) --- src/gui/selectprofileform.cpp | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/gui/selectprofileform.cpp b/src/gui/selectprofileform.cpp index 8b41c35..f93384a 100644 --- a/src/gui/selectprofileform.cpp +++ b/src/gui/selectprofileform.cpp @@ -106,7 +106,7 @@ int SelectProfileForm::execForm() "Before you can use Twinkle, you must create a user "\ "profile.
Click OK to create a profile.")); - int newProfileMethod = QMessageBox::question(this, PRODUCT_NAME, tr( + QMessageBox mb(QMessageBox::Question, PRODUCT_NAME, tr( ""\ "You can use the profile editor to create a profile. "\ "With the profile editor you can change many settings "\ @@ -121,23 +121,29 @@ int SelectProfileForm::execForm() "calls to regular and cell phones and send SMS messages.

") #endif + tr("Choose what method you wish to use."), - tr("&Wizard"), tr("&Profile editor") + QMessageBox::NoButton, this); + QPushButton *wizardButton = mb.addButton( + tr("&Wizard"), + QMessageBox::AcceptRole); + QPushButton *editorButton = mb.addButton( + tr("&Profile editor"), + QMessageBox::AcceptRole); #ifdef WITH_DIAMONDCARD - , tr("&Diamondcard") + QPushButton *diamondCardButton = mb.addButton( + tr("&Diamondcard"), + QMessageBox::AcceptRole); #endif - ); + mb.exec(); - switch (newProfileMethod) { - case 0: + if (mb.clickedButton() == wizardButton) { wizardProfile(true); - break; - case 1: + } else if (mb.clickedButton() == editorButton) { newProfile(true); - break; - case 2: +#ifdef WITH_DIAMONDCARD + } else if (mb.clickedButton() == diamondCardButton) { diamondcardProfile(true); - break; - default: +#endif + } else { return QDialog::Rejected; }