Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    [SOLVED] compile error with QMessageBox::clickedButton() == QPushButton* in VS2012

    General and Desktop
    2
    4
    3789
    Loading More Posts
    • 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.
    • S
      scarleton last edited by

      I am in the process up upgrading my code from Qt4.7 w/ VS2008 to Qt5 w/ VS2012. The very last compile error I am getting is with regards to checking which custom button was clicked on a QMessageBox. Here is the code:

      @QPushButton *renameButton = msgBox.addButton(tr("Rename"), QMessageBox::ActionRole);
      QPushButton *deleteButton = msgBox.addButton(tr("Delete"), QMessageBox::DestructiveRole);
      msgBox.addButton(QMessageBox::Cancel);

      msgBox.exec();

      if( msgBox.clickedButton() == deleteButton)
      {
      }
      @

      The issue is in the final if statement, I get the error:

      error C2440: '==' : cannot convert from 'QPushButton *' to 'QAbstractButton *'

      I have tried qobject_casting the clickedButton to a QPushButton:

      @QPushButton *clickedButton = qobject_cast<QPushButton *>(msgBox.clickedButton());@

      But I get this error:

      'qobject_cast' : none of the 2 overloads could convert all the argument types

      Any suggestions on how to fix this?

      1 Reply Last reply Reply Quote 2
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        Did you @#include <QPushButton>@ ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 1
        • S
          scarleton last edited by

          WOW, that was it. Thank you.

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            You're welcome !

            Don't forget to update the thread's title to solved so other forum users may know that a solution has been found :)

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 0
            • First post
              Last post