2

I am attempting to subclass a QLabel using a header file and I get the error on constructor

IntelliSense: indirect nonvirtual base class is not allowed

class foo : public QLabel
{
    Q_OBJECT

    foo(QWidget* parent = 0) :  QWidget(parent)
    {

    }

    void mouseMoveEvent( QMouseEvent * event )
    {
        //Capture this
    }

};

Any suggestions why this is happening and how I can fix it ?

László Papp
  • 51,870
  • 39
  • 111
  • 135
Rajeshwar
  • 11,179
  • 26
  • 86
  • 158

1 Answers1

2

The problem is here:

foo(QWidget* parent = 0) :  QWidget(parent)

You are inheriting from QLabel, but you specify QWidget for the base. You should write this intead:

explicit foo(QWidget* parent = Q_NULLPTR) :  QLabel(parent)
//                                           ^^^^^^

Also, please use explicit for that constructor as well as Q_NULL_PTR or at least NULL instead of 0.

László Papp
  • 51,870
  • 39
  • 111
  • 135