[Qt-interest] remove QgRaphicsItem from parent
Josiah Bryan
jbryan at productiveconcepts.com
Mon Oct 12 12:58:18 CEST 2009
Riccardo Roasio wrote:
> I believe you ...
>
> but using this code:
>
> while (! elements.isEmpty ())
> {
> delete elements.takeFirst ();
> }
>
> update();
>
> the elements still exist on the screen.....
>
>
I probably would do:
while (! elements.isEmpty ())
{
pointer = elements.takeFirst ();
pointer->setParent(0);
myGraphicsScene->removeItem(pointer);
delete pointer;
}
Docs say setParent(0) sets removes the item from it's current parent and
makes it a child of the QGraphicsScene (e.g. no parent.) Then we can
call removeItem() on the graphics scene to get it removed. Finally, we
can delete the pointer once we're done with it.
Seems to work for me in my projects.
Cheers!
-josiah
> Riccardo
>
> 2009/10/8 Rainer Wiesenfarth <Rainer.Wiesenfarth at inpho.de>:
>
>> From: Riccardo Roasio [mailto:riccardo.roasio at gmail.com]
>>
>>> I know....
>>>
>>> after doing a ~GGraphicsItem
>>>
>>> i do a elemenents.clear so the problem is not present..
>>> [...]
>>>
>> As I said, you should _almost_never_ call a destructor like you do with
>> "e->~QGraphicsItem();" (unless you know exactly what you are doing). Believe
>> me, you want to use "delete e;" instead.
>>
>> Best Regards / Mit freundlichen Grüßen
>> Rainer Wiesenfarth
>>
>> --
>> INPHO GmbH * Smaragdweg 1 * 70174 Stuttgart * Germany
>> phone: +49 711 2288 10 * fax: +49 711 2288 111 * web: www.inpho.de
>> place of business: Stuttgart * managing director: Johannes Saile
>> commercial register: Stuttgart, HRB 9586
>> Leader in Photogrammetry and Digital Surface Modelling
>>
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>
>>
>>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
More information about the Qt-interest-old
mailing list