PDA

View Full Version : layout->children() of size 0, even after layout->addWidget



quimnuss
18th March 2016, 13:25
Does layout->children() not include QWidgets added with addWidget?



QWidget* wid = new QWidget();
formLayout->addWidget(wid);
QList<QObject*> blah = formLayout->children();
qDebug() << blah << " - blah - " << blah.size();


Size is 0 and blah is empty.

However, its parent childern does include the added widget. So ->addWidget() doesn't set the layout as parent but the layout's parent? Are layouts then assumed to never be parents?

How can I add QWidgets to a layout so that I can use findChild by its name?

Cheers

anda_skoa
18th March 2016, 15:08
Does layout->children() not include QWidgets added with addWidget?

No.

The parent of a widget is either 0 or another widget.
So QLayout is never a parent of a widget, so widget's never appear in a layout's children() list.



How can I add QWidgets to a layout so that I can use findChild by its name?

The layout is just arranging widgets on behalf of a parent widget, which you can use as a starting point for findChild().

Chers,
_