Yes... and you can try this for yourself with a short program. Each QObject emits the QObject::destroyed() signal as it is destroyed, and the QObject parent (if there is one) uses this to remove the disappearing QObject from its list of children.
#include <QtCore>
#include <QDebug>
Q_OBJECT
public:
qDebug() << "Creating object" << s << "parent" << p;
setObjectName(s);
}
~Object() {
qDebug() << "Destroying" << objectName() << "with children" << children();
}
};
int main(int argc, char **argv)
{
Object parent("Parent");
Object o1("Stack child", &parent);
Object *h1 = new Object("Heap Child 1", &parent);
Object *h2 = new Object("Heap Child 2", &parent);
delete h1;
qDebug() << "Bye!";
return 0;
}
#include "main.moc"
#include <QtCore>
#include <QDebug>
class Object: public QObject {
Q_OBJECT
public:
Object(const QString &s, QObject *p = 0): QObject(p) {
qDebug() << "Creating object" << s << "parent" << p;
setObjectName(s);
}
~Object() {
qDebug() << "Destroying" << objectName() << "with children" << children();
}
};
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
Object parent("Parent");
Object o1("Stack child", &parent);
Object *h1 = new Object("Heap Child 1", &parent);
Object *h2 = new Object("Heap Child 2", &parent);
delete h1;
qDebug() << "Bye!";
return 0;
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks