PDA

View Full Version : Delete Layout and its childs



jano_alex_es
8th May 2009, 12:06
Hi, another problem... :S

I have a QScrollArea with a layout set.

In execution, I create some checkboxes, that I add to the lyout.



QCheckBox* pChk = 0;
for(int i = 0; i < myList.count(); ++i)
{
pChk = new QCheckBox(info);
my_Lyout->addWidget(pChk);
}



I have the

ui.my_scrollArea->setLayout(my_Lyout);

in the constructor.

I'd like to destroy all the checkboxes when the destructor is called:



CAddGroup::~CAddGroup()
{
for(int i = 0; i < my_Lyout->count(); ++i)
{
QLayoutItem* pChk = my_Lyout->itemAt(i);
delete pChk;
pChk = 0;
}

delete(ui.my_scrollArea->layout());

m_pVLayGroups = 0;
}


But delete(ui.m_srcUsers->layout()); gives me an out of memory exception.

any idea?

thanks!

wysota
8th May 2009, 12:23
You should use QScrollArea::setWidget() to set the widget on the scroll area and then you can just delete this widget and its children (the checkboxes) will be deleted as well.