Question

Say I have something like this

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

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

Was it helpful?

Solution

From http://qt-project.org/doc/qt-4.8/layout.html:

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top