Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 5

Qt-interest Archive, April 2007
QGraphicsScene removing graphicsitems from scene


Message 1 in thread

Hi,

Iam having difficulties removing all my QGraphicsItem objects from
the scene,

I tried scene->removeItem(node->item); which complains about the scene 
and items scene not beeing the same scene. Alright then i tried this 
after some help from #qt@freenode

while(scene->items().first()){
	delete scene->items(); or i also tried 	

         qDeleteAll(scene->items());
}

this gives me segfault.

some clarification i want when a user has finished a simulation to clear 
the scene for all items.
my items are contained in a class node which has QGraphicsItem* members 
item etc.

Can anyone help me give me som feedback on a easy way to remove the 
items from scene.


thanks in advance.

--
 [ signature omitted ] 

Message 2 in thread

Hello,

portedcanvas example from Qt4.2 have the following code for clear scene:


    QList<QGraphicsItem *> list = scene()->items();
    QList<QGraphicsItem *>::Iterator it = list.begin();
    for (; it != list.end(); ++it) {
        if ( *it )
            delete *it;
    }

suleiman wrote:
> Hi,
>
> Iam having difficulties removing all my QGraphicsItem objects from
> the scene,
>
> I tried scene->removeItem(node->item); which complains about the scene
> and items scene not beeing the same scene. Alright then i tried this
> after some help from #qt@freenode
>
> while(scene->items().first()){
>     delete scene->items(); or i also tried    
>
>         qDeleteAll(scene->items());
> }
>
> this gives me segfault.
>
> some clarification i want when a user has finished a simulation to
> clear the scene for all items.
> my items are contained in a class node which has QGraphicsItem*
> members item etc.
>
> Can anyone help me give me som feedback on a easy way to remove the
> items from scene.
>
>
> thanks in advance.
>
> -- 
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
> !DSPAM:46275dd8189002018316037!
>

--
 [ signature omitted ]