Hello,
I'd like to remove a widget from the layout and delete it.
for this I'd like to use the following source code
...
int cnt;
QLayoutItem *it;
MyWidget *w;
cnt = aVLayout->count();
for( int i = 0; i < cnt; i++ )
{
it = aVLayout->itemAt(0);
w = ((MyWidget *)(it->widget()));
aVLayout->removeWidget( w );
delete w;
aVLayout->removeItem( it );
delete it; // SEGMENTATION VIOLATION CRASH!!!
}
My questions:
- Is it necessary to remove and delete the QLayoutItem item?
- how to do it to avoid the crash?
In my understanding, the QLayoutItem has been created and added, when the addWidget() method has been called, so when I am removing a widget from the layout and deleting it, also the QLayoutItem shall be removed and deleted. Is it correct?
I am using Qt 4.6.3
Thx for your help
Bookmarks