qt creator - Qt Parent Child Relationships -
qt creator - Qt Parent Child Relationships -
i'm running test understand parent/child relationships in qt , have question how can view these relationships in qt creator debugger.
when start demo application, here debugger shows:
because phone call qt's dumpobjecttree() before add together widgets, tree empty, except mainwindow's layout. that's expected.
when close application, , ~mainwindow destructor called, phone call dumpobjecttree() again, time, of widgets created show in tree. if called dumpobjecttree() after window destroyed, shouldn't tree empty again?
am not destroying kid widgets correctly, or misunderstand info displayed dumpobjectree() function?
mainwindow::mainwindow(qwidget *parent) : qmainwindow(parent) { qdebug() << "window initialized-------------"; dumpobjecttree(); this->buildlayout(); } void mainwindow::buildlayout() { qwidget *window = new qwidget(this); this->setobjectname("main window"); layout = new qvboxlayout(); qsplitter *split = new qsplitter(); split->setobjectname("horizontal split"); split->setorientation(qt::horizontal); qtextedit *editor1 = new qtextedit(); editor1->setobjectname("editor 1"); qtextedit *editor2 = new qtextedit(); editor2->setobjectname("editor 2"); split->addwidget(editor1); split->addwidget(editor2); qsplitter *split2 = new qsplitter(); split2->setobjectname("vertical split"); split2->setorientation(qt::vertical); qtextedit *editor3 = new qtextedit(); editor3->setobjectname("editor 3"); split2->addwidget(split); split2->addwidget(editor3); qtoolbar *maintoolbar = new qtoolbar(); maintoolbar->setobjectname("main toolbar"); maintoolbar->addaction("main button 1"); maintoolbar->addseparator(); maintoolbar->addaction("main button 2"); maintoolbar->setmovable(true); layout->addwidget(maintoolbar); layout->addwidget(split2); qtoolbar *toolbar = new qtoolbar(this); toolbar->setobjectname("mini toolbar"); toolbar->addaction("button 1"); toolbar->addseparator(); toolbar->addaction("button 2"); toolbar->setmovable(true); qmenubar *menu = new qmenubar(this); menu->setobjectname("menu bar"); menu->addaction("menu 1"); menu->addaction("menu 2"); menu->addaction("menu 3"); window->setlayout(layout); mainwindow::addtoolbar(toolbar); mainwindow::setmenubar(menu); mainwindow::setcentralwidget(window); } mainwindow::~mainwindow() { delete layout; qdebug() << "destroyed " << this->metaobject()->classname(); qdebug() << "object tree-------------"; dumpobjecttree(); qdebug() << "object info-------------"; dumpobjectinfo(); }
thanks
your confusion when mainwindow
destructor called, window part of way through beingness destroyed.
in particular, kid widgets not deleted through parent-child mechanism until qobject
destructor called, occurs after that, @ point phone call dumpobjecttree() children still exist.
qt qt-creator
Comments
Post a Comment