void func()
{
QObject* obj1 = new QObject();
QObject* obj2 = new QObject();
QObject* obj3 = new QObject();
obj2->setParent(obj1);
obj3->setParent(obj1);
qDebug() << "obj1 = " << obj1 << endl;
qDebug() << "obj2 = " << obj2 << endl;
qDebug() << "obj3 = " << obj3 << endl;
const QObjectList& list = obj1->children();
for(int i=0; i<list.length(); i++)
{
qDebug() << list[i];
}
}
setparents()
QObject* obj1 = new QObject();
QObject* obj2 = new QObject();
QObject* obj3 = new QObject();
QObject* obj4 = new QObject();
obj2->setParent(obj1);
obj3->setParent(obj1);
obj4->setParent(obj3);
qDebug() << "obj1 = " << obj1;
qDebug() << "obj2 = " << obj2;
qDebug() << "obj3 = " << obj3;
qDebug() << "obj4 = " << obj4;
const QObjectList& list = obj1->children() ;
for(int i=0; i<list.length(); i++)
{
qDebug() << list[i];
}
qDebug() << "Delete...";
delete obj3;
fo
注:笔记记录于狄泰软件学院课程