Simplicity
Simplicity

Reputation: 48966

C++ constructor and Qt

There is a statement in the foudations of Qt Development book that goes as follows:

MyClass::MyClass(const string& test, QObject *parent) : QObject( parent )

What is meant when we put : QObject( parent )?

Thanks.

Upvotes: 1

Views: 5855

Answers (3)

graphite
graphite

Reputation: 2960

When you create a QObject with another object as parent, it's added to the parent's children() list, and is deleted when the parent is.

Reference

Upvotes: 0

the JinX
the JinX

Reputation: 1980

In short this means that MyClass inherits properties (and methods) from QObject

http://www.cplusplus.com/doc/tutorial/inheritance/

http://www.anyexample.com/programming/cplusplus/cplusplus_inheritance_example.xml

So MyClass is a QObject

Upvotes: 0

Michael Aaron Safyan
Michael Aaron Safyan

Reputation: 95629

Are you sure that there aren't two constructor declarations? The : QObject(parent) is an initializer list; it is initializing the base class QObject with the QObject::QObject(QObject*) constructor.

Upvotes: 3

Related Questions