Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-44131

QMessageBox::​addButton assigns wrong roles to added custom buttons

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • 5.12
    • 5.4.0, 5.12.0
    • None
    • Qt 5.4.0 x64 (MSVC2013)
      Windows 8.1 Pro x64
    • All
    • d8bbb5ee0e60d44a70d29306e607a59caf7fe5bc

    Description

      When using QMessageBox::​addButton(QAbstractButton * button, ButtonRole role), the roles specified are not respected.

      The following code creates a message box and sets 3 custom buttons.
      When executed, the button that, when clicked, prints "Accepted!" is btn_reject_1. It should be, instead, btn_accept.
      If you change the order of the buttons when adding them, you'll see that, no matter what the role assigned, the second button is always the one which ends up getting the AcceptRole (that is, causes the debug to be printed)

      QMessageBox mb;
      mb.setIcon(QMessageBox::Warning);
      mb.setWindowTitle("Bug");
      mb.setText("Is this a bug?");
      QPushButton btn_accept("Accept");
      QPushButton btn_reject_1("Reject 1");
      QPushButton btn_reject_2("Reject 2");
      mb.addButton(&btn_accept, QMessageBox::YesRole);
      mb.addButton(&btn_reject_1, QMessageBox::NoRole);
      mb.addButton(&btn_reject_2, QMessageBox::RejectRole);
      connect(&mb, &QMessageBox::accepted, []()->void{qDebug()<<"Accepted!";});
      mb.exec();
      
      5.12.0 xcb/Ubuntu 17.10, fusion ()
      
      Rejected!
      ret= 0 clickedButton= QPushButton(0x5606f0d37cb0, name="Accept/YesRole")
      
      Accepted!
      ret= 1 clickedButton= QPushButton(0x55a0b50ff6d0, name="Reject 1/NoRole")
      
      ret= 2 clickedButton= QPushButton(0x55ac3d5aa520, name="Reject 2/RejectRole")
      

      Attachments

        For Gerrit Dashboard: QTBUG-44131
        # Subject Branch Project Status CR V

        Activity

          People

            vitaly.fanaskov Vitaly Fanaskov
            jubba Claudio Barutta
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes