[Qt-interest] Problem with adding/removing/adding elements in a QVBoxLayout
Karol Krizka
kkrizka at gmail.com
Wed May 20 07:05:21 CEST 2009
On Tue, 2009-05-19 at 11:33 -0500, Juan Pablo Crossley wrote:
> Finally!
>
> I solved this, the problem was with the memory deletion of the child
> widget,
>
> QVBoxLayout* box = (QVBoxLayout*)layout();
>
> QLayoutItem* item;
> while ((item = box->takeAt(0)) != 0) {
> box->removeWidget(item->widget());
> delete item->widget(); <<<---- very important step!!!!
> }
>
> After removing the widget using the "removeWidget" you must delete the
> item, so I combined the removeWidget with the delete and it did the
> trick.
>
You might want to do:
item->widget()->deleteLater();
This deletes the widget next time Qt events are processed, in case there
are stale events from the widget. Not doing so sometimes leads to the
program crashing, at least according to my experience.
--
Cheers,
Karol Krizka
http://www.krizka.net
More information about the Qt-interest-old
mailing list