Results 1 to 6 of 6

Thread: Garbage collection

  1. #1
    Join Date
    Jul 2010
    Posts
    12
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Arrow Garbage collection

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Garbage collection

    The scene takes ownership. You don't need to delete the items yourself.

  3. The following user says thank you to tbscope for this useful post:

    Septi (6th July 2010)

  4. #3
    Join Date
    Jul 2010
    Posts
    12
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Garbage collection

    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?

  5. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Garbage collection

    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

  6. #5
    Join Date
    Jul 2010
    Posts
    12
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Garbage collection

    Okay, I see, thanks.

    Quote Originally Posted by tbscope View Post
    and if you want to have several lists, one for rectangles, one for text etc... you can always subclass the scene of course
    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.

  7. #6
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Garbage collection

    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

Similar Threads

  1. QString, QStringList and garbage collection...
    By PaladinKnight in forum Newbie
    Replies: 4
    Last Post: 5th April 2010, 16:22
  2. qRegisterMetaType: getting garbage through signal/slot
    By zlacelle in forum Qt Programming
    Replies: 1
    Last Post: 16th June 2009, 09:05
  3. Q3ScrollView resists to scroll down to the garbage bin
    By sivrisinek in forum Qt Programming
    Replies: 0
    Last Post: 5th February 2009, 17:50
  4. question about garbage collection
    By Dumbledore in forum Qt Programming
    Replies: 4
    Last Post: 18th December 2007, 22:08
  5. lib using Image Collection
    By bitChanger in forum Qt Programming
    Replies: 4
    Last Post: 25th July 2006, 17:30

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.