Hi,
I have classes inherited from QWidget.
class MyWidget : public QWidget
{
----------- Methods -------
public slots :
void setEnabled(bool value);
}
QWidget* myWidget = new MyWidget(...);
myWidget->setEnabled(false);
// this will call to setEnabled(..) of QWidget I want it to callhere MyWidget's setEnabled(...).
Please let me know if I am missing something here.


Reply With Quote


Here it is: for polymorphism to work, the overridden method has to be virtual (or pure virtual) in the parent class, which is not the case for QWidget::setEnabled(). In addition, you have to call the method using a pointer (or reference, i.e. address-of operator "&"), as you have done. So, you could sub-class QWidget and declare a virtual setEnabled() method, then sub-class that class and implement setEnabled() there. If this is too much bother for a polymorphic setEnabled(), then you'll have to cast myWidget back to a MyWidget * and then call setEnabled(), as follows:

Bookmarks