Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. (QDialog::DialogCode) QMessageBox.result() return enum value
Qt 6.11 is out! See what's new in the release blog

(QDialog::DialogCode) QMessageBox.result() return enum value

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 48 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MilesM
    wrote last edited by
    #1

    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

    JonBJ 1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote last edited by
      #2

      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."

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2
      • M MilesM

        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

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote last edited by
        #3

        @MilesM
        I was just about to write same as @Christian-Ehrlicher has :)

        So in your helper just change return (QDialog::DialogCode)msgbox.result(); to do an if/switch on the StandardButton values returning the appropriate DialogCode.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved