开发者

C++ constructor and Qt

开发者 https://www.devze.com 2023-02-13 22:24 出处:网络
There is a statement in the foudations of Qt Development book that goes as follows: MyClass::MyClass(const string& test, QObject *parent) : QObject( parent )

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开发者_JAVA百科 : QObject( parent )?

Thanks.


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.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消