Does QLayout::addWidget assign a parent
Asked Answered
A

1

5

Say I have something like this:

void someClass::start()
{
    QLabel* label = new QLabel();
    label->setText("Hello World");
    ui.verticalLayout->addWidget(label);
}

Does addWidget make label a child of someClass so that when I delete someClass, label is also deleted? If this is true, how do I know which methods in general assign parents to an object?

Amid answered 31/12, 2013 at 7:45 Comment(1)
In addition to the Violet's useful answer, you can always check yourself whether if a QObject has a parent, but calling the parent() method.Ogee
R
9

From Qt Documentation — Layout Management — Tips for Using Layouts:

When you use a layout, you do not need to pass a parent when constructing the child widgets. The layout will automatically reparent the widgets (using QWidget::setParent()) so that they are children of the widget on which the layout is installed.

Rosas answered 31/12, 2013 at 7:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.