Does QGraphicsScene delete all the graphic items/widgets/layouts upon deletion, or should I take care of them?
Because I don't need to access most of them, so I feel it's pointless to keep the pointers.
Does QGraphicsScene delete all the graphic items/widgets/layouts upon deletion, or should I take care of them?
Because I don't need to access most of them, so I feel it's pointless to keep the pointers.
The scene takes ownership. You don't need to delete the items yourself.
Septi (6th July 2010)
tbscope, thanks!
By the way, that means that if I decide to keep some pointers, they will become invalid, when scene gets deleted, or null, if they're smart pointers (QPointer), doesn't it?
Yes
Be carefull with that. There's nothing wrong with keeping a list to all the objects but before using them check if they are valid. But I guess you already know that.
Edit: not that there is a reason to keep a list on your own, the scene already does that for you.
Edit 2: and if you want to have several lists, one for rectangles, one for text etc... you can always subclass the scene of course
Okay, I see, thanks.
You mean by keeping a list of needed items inside a scene, reimplementing functions to add items and adding a function to retrieve the list? If so, in my case it's probably easier to just keep that list outside of QGraphicsScene, it's only used from outside anyway.
No, I mean return a list of rectangles for example.
You keep the items list of the scene unchanged. But you use that list to return more information.
Pseudo code example:
foreach item in scene items
{
if item = rectangle
add to custom list
}
return custom list
Bookmarks