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. [SOLVED] compile error with QMessageBox::clickedButton() == QPushButton* in VS2012

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

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 4.1k 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.
  • S Offline
    S Offline
    scarleton
    wrote on last edited by
    #1

    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
    2
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      1
      • S Offline
        S Offline
        scarleton
        wrote on last edited by
        #3

        WOW, that was it. Thank you.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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
          0

          • Login

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