C++ (Qt)new QLabel( &widget ); // here
C++ (Qt)QLabel lbl = new QLabel( &widget ); // here
QObject::~QObject(){ ..... if (!d->children.isEmpty()) d->deleteChildren(); qt_removeObject(this); .....}void QObjectPrivate::deleteChildren(){ const bool reallyWasDeleted = wasDeleted; wasDeleted = true; // delete children objects // don't use qDeleteAll as the destructor of the child might // delete siblings for (int i = 0; i < children.count(); ++i) { currentChildBeingDeleted = children.at(i); children[i] = 0; delete currentChildBeingDeleted; } children.clear(); currentChildBeingDeleted = 0; wasDeleted = reallyWasDeleted;}
virtual ~QObject();
class Foo: public QObject{ enum{size = 100}; int* m_data;public: Foo(QObject* pobj = 0):QObject(pobj){ m_data = new int[size]; } ~Foo(){ delete []m_data; std::cout << "Foo destructor" << std::endl; }};int main(int argc, char *argv[]){ QObject* pobj = new Foo; //do something... delete pobj;//вызывается деструктор Foo}
QObject* pobj = new Foo;
Foo* pobj = new Foo;
typedef QList<QObject*> QObjectList;