KShots
16th October 2007, 16:20
Hello all... I've been getting confused on the parent() heirarchy. Here's what I've got:
formMainWindow, parent of QMdiArea, parent of QMdiSubWindow, parent of subWidget
I can use this code to initialize (from within the formMainWindow):
QMdiArea * ws = new QMdiArea(this);
subWidget * w = new subWidget;
QMdiSubWindow * sw = ws->addSubWindow(w); // Should set w->parent() to sw
I *think* this works all right... but traversing the heirarchy is another matter. From within subWidget:
QMdiSubWindow * sw = dynamic_cast<QMdiSubWindow *>(parent()); // Returns a valid pointer
QMdiArea * ws = dynamic_cast<QMdiArea *>(sw->parent()); // Returns NULL
formMainWindow * mw = dynamic_cast<formMainWindow *>(sw->parent()); // Also returns NULLSo... what is the parent of a QMdiSubWindow? How can I traverse the heirarchy back to the formMainWindow?
formMainWindow, parent of QMdiArea, parent of QMdiSubWindow, parent of subWidget
I can use this code to initialize (from within the formMainWindow):
QMdiArea * ws = new QMdiArea(this);
subWidget * w = new subWidget;
QMdiSubWindow * sw = ws->addSubWindow(w); // Should set w->parent() to sw
I *think* this works all right... but traversing the heirarchy is another matter. From within subWidget:
QMdiSubWindow * sw = dynamic_cast<QMdiSubWindow *>(parent()); // Returns a valid pointer
QMdiArea * ws = dynamic_cast<QMdiArea *>(sw->parent()); // Returns NULL
formMainWindow * mw = dynamic_cast<formMainWindow *>(sw->parent()); // Also returns NULLSo... what is the parent of a QMdiSubWindow? How can I traverse the heirarchy back to the formMainWindow?