[Qt-interest] QFormLayout memory leak??

Bradley Smith bradley at baysmith.com
Thu Nov 19 07:54:03 CET 2009


> void MainWindow::on_pushButton_2_clicked()
> {
>     QFormLayout *form = ui->formLayout;
>     QLayoutItem *child;
>     while( (form->count() > 0) && ((child = form->takeAt( 0 )) != 0) ) {
           delete child->widget
();                                                                 //
Try adding this line
>         delete child;
>     }
>
> }
>
> I click the first button which adds the elements and the second removes them but they are not removed from the UI.  If I click the first button again, the labels appear to change to bold and become more bold as you click the add and delete buttons.

The QLayoutItem is being taken and deleted, but not the QWidget
associated with the layout item. Try adding the line shown in the code
above.

  Bradley




More information about the Qt-interest-old mailing list