4

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 ?

László Papp
  • 51,870
  • 39
  • 111
  • 135
MistyD
  • 16,373
  • 40
  • 138
  • 240
  • 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. – László Papp Dec 31 '13 at 08:03

1 Answers1

8

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.

Violet Giraffe
  • 32,368
  • 48
  • 194
  • 335