[Solved]delete Groupbox, delete linked widgets too?



  • Hello
    When I have a QGroupbox with have a layout which have widgets, and I delete the Groupbox, have I to delete the other widgets too or get they automatically deleted?

    @
    QVBoxLayout *boxLayout = new QVBoxLayout;
    QLabel *label1 = new QLabel;
    QLabel *label2 = new QLabel;
    boxLayout->addWidget(label1);
    boxLayout->addWidget(label2);
    QGroupBox *groupBox = new QGroupBox;
    groupBox->setLayout(boxLayout);
    delete groupBox;
    @
    Are now label1, label2 and boxLayout deleted too?


  • Moderators

    Whenever you delete a widget (or any other QObject descendant) all of it's children get deleted too. Layout contents automatically become children of the widget you set that layout on.
    If everything has a parent or is part of an assigned layout the only thing you need to delete is the top most widget(except when it is the last remaining widget or has a flag delete on close set, in which case it also gets deleted automatically).


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.