PDA

View Full Version : remove QVBoxLayout content in QHBoxLayout



jackajack01
2nd August 2012, 14:47
Hi!

I have a QHBoxLayout in which I store QVBoxLayout, but I want to delete at any given time. For this use the following method:

if (layerH)// QHBoxLayout
{
while(layerH->takeAt(0) != 0)
{
layerH->removeItem(layerH->takeAt(0));
delete layerH->takeAt(0);
}
}

The problem is that after executing this function the QVBoxLayout are still present.

any idea how to fix this?

high_flyer
6th August 2012, 11:53
Follow your code:
your first line in the while() loop removes the first item in the layout - but you don't store the pointer to the removed item (which is also a memory leak), and now the first item is the next item.
Then, in the second line, you are deleting the current first item, which due to the first line is actually the second item.
So you are deleting every second item, and removing every first.
And please use code tags.