In order to react to an event in the Qt framework I have reimplemented a Qt class (QLabel), i.e. its default constructor with a single argument. Since that gave an error, I also reimplemented the constructor with an additional argument. Now it works.
Class:
class myLabel : public QLabel
{
Q_OBJECT
public:
explicit myLabel(QWidget *parent = 0);
explicit myLabel(QString x, QWidget *parent = 0);
void mousePressEvent( QMouseEvent* e );
signals:
void clicked();
};
Constructors:
myLabel::myLabel(QWidget *parent) : QLabel(parent)
{
}
myLabel::myLabel(QString x, QWidget *parent) : QLabel(parent)
{
setText(x);
}
My (beginner) question is: why isn't the respective constructor of the base class run, as with all other methods [of the base class (e.g. I can use setText() without reimplementing it)]? And the extreme: why do I need to reimplement a constructor at all, although it does not contain any code?
Edit: Before posting, I was not sure what to search for, but this question has essentially been answered in https://stackoverflow.com/a/347362/1619432
Edit: As bartimar pointed out, the constructor is not empty in that it calls the base class' constructor. This can apparently be done with passing the respective parameters like so:
myLabel::myLabel( const QString& x, QWidget* parent, Qt::WindowFlags f ) :
QLabel( x, parent, f ) {}