(QDialog::DialogCode) QMessageBox.result() return enum value
-
So I have QMessageBox / QDialog::DialogCode to help with some dialogue pop-up confirmations. The method is written out like the following
QDialog::DialogCode dialog_helper::confirm_clear_dialog() { QMessageBox msgbox(QMessageBox::Icon::Question,"Confirm", "Are you sure you want to clear?"); msgbox.addButton("No",QMessageBox::RejectRole); msgbox.addButton("Yes",QMessageBox::AcceptRole); msgbox.exec(); return (QDialog::DialogCode)msgbox.result(); } void table_view_t::clearTableCommand() { if(dialog_helper::confirm_clear_dialog() == QDialog::DialogCode::Accepted) { table_model->clear_clearTable(); } }In the past these methods seemed to work as expected, and accepting the dialogue would get past the dialog_helper::confirm_clear_dialog() == QDialog::DialogCode::Accepted comparison on older versions of QT. However, ever since we upgraded to QT 6.8.7, this interaction seems to be broken. Now the QMessageBox return value always seems to return an enum value of 3 and 4 for accepted and rejected but QDialog::DialogCode only contains 2 enum values (0 and 1) thus the comparison can never be true.
I played around with it without much success but is there a simple refactor to fix this interaction, preferably on the helper method side. All of the other forums I've seen seem to parrot that this should work.
Thank you
-
Please see the documentation at https://doc.qt.io/qt-6/qmessagebox.html#exec , especially the note:
"Note: The result() function returns also StandardButton value instead of QDialog::DialogCode."
-
So I have QMessageBox / QDialog::DialogCode to help with some dialogue pop-up confirmations. The method is written out like the following
QDialog::DialogCode dialog_helper::confirm_clear_dialog() { QMessageBox msgbox(QMessageBox::Icon::Question,"Confirm", "Are you sure you want to clear?"); msgbox.addButton("No",QMessageBox::RejectRole); msgbox.addButton("Yes",QMessageBox::AcceptRole); msgbox.exec(); return (QDialog::DialogCode)msgbox.result(); } void table_view_t::clearTableCommand() { if(dialog_helper::confirm_clear_dialog() == QDialog::DialogCode::Accepted) { table_model->clear_clearTable(); } }In the past these methods seemed to work as expected, and accepting the dialogue would get past the dialog_helper::confirm_clear_dialog() == QDialog::DialogCode::Accepted comparison on older versions of QT. However, ever since we upgraded to QT 6.8.7, this interaction seems to be broken. Now the QMessageBox return value always seems to return an enum value of 3 and 4 for accepted and rejected but QDialog::DialogCode only contains 2 enum values (0 and 1) thus the comparison can never be true.
I played around with it without much success but is there a simple refactor to fix this interaction, preferably on the helper method side. All of the other forums I've seen seem to parrot that this should work.
Thank you