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. Unexpected return value from QMessageBox::exec()

Unexpected return value from QMessageBox::exec()

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 4 Posters 385 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.
  • W Offline
    W Offline
    walle19
    wrote on last edited by
    #1

    Hi All,
    My platform: Linux kubuntu 14
    QT Version: 4.7.1

    I generate a QMessageBox with two standard buttons as seen in the following code:

    
       QMessageBox msgBox;
        msgBox.addButton(tr(sn.c_str()), QMessageBox::NoRole);
        msgBox.addButton(tr(sn.c_str()), QMessageBox::YesRole);
    
        int ret = msgBox.exec();
        switch (ret) {
        case QMessageBox::YesRole:
        {
           break;
        }
        case QMessageBox::NoRole:
        {
        	break;
        }
        default:
        	break;
        }
    
    

    This code generates a qmessagebox with two buttons.
    When I press the right button QMessageBox::NoRole the return value from exec() is zero;
    Even though the documentation states:
    When using a QMessageBox with standard buttons, this functions returns a StandardButton value indicating the standard button that was clicked.

    Any idea what I am doing wrong ?

    Thanks

    jsulmJ VRoninV 2 Replies Last reply
    0
    • W walle19

      Hi All,
      My platform: Linux kubuntu 14
      QT Version: 4.7.1

      I generate a QMessageBox with two standard buttons as seen in the following code:

      
         QMessageBox msgBox;
          msgBox.addButton(tr(sn.c_str()), QMessageBox::NoRole);
          msgBox.addButton(tr(sn.c_str()), QMessageBox::YesRole);
      
          int ret = msgBox.exec();
          switch (ret) {
          case QMessageBox::YesRole:
          {
             break;
          }
          case QMessageBox::NoRole:
          {
          	break;
          }
          default:
          	break;
          }
      
      

      This code generates a qmessagebox with two buttons.
      When I press the right button QMessageBox::NoRole the return value from exec() is zero;
      Even though the documentation states:
      When using a QMessageBox with standard buttons, this functions returns a StandardButton value indicating the standard button that was clicked.

      Any idea what I am doing wrong ?

      Thanks

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @walle19 You should at least try with the latest Qt4 version (which is 4.8.7 if I remember correctly).

      https://forum.qt.io/topic/113070/qt-code-of-conduct

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

        Since you don't call the QMessageButton with StandardButtons you have to use clickedButton() to determine the selected button.

        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
        4
        • W walle19

          Hi All,
          My platform: Linux kubuntu 14
          QT Version: 4.7.1

          I generate a QMessageBox with two standard buttons as seen in the following code:

          
             QMessageBox msgBox;
              msgBox.addButton(tr(sn.c_str()), QMessageBox::NoRole);
              msgBox.addButton(tr(sn.c_str()), QMessageBox::YesRole);
          
              int ret = msgBox.exec();
              switch (ret) {
              case QMessageBox::YesRole:
              {
                 break;
              }
              case QMessageBox::NoRole:
              {
              	break;
              }
              default:
              	break;
              }
          
          

          This code generates a qmessagebox with two buttons.
          When I press the right button QMessageBox::NoRole the return value from exec() is zero;
          Even though the documentation states:
          When using a QMessageBox with standard buttons, this functions returns a StandardButton value indicating the standard button that was clicked.

          Any idea what I am doing wrong ?

          Thanks

          VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          Side note:

          @walle19 said in Unexpected return value from QMessageBox::exec():

          tr(sn.c_str())

          This is not how it works

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          6

          • Login

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