Results 1 to 8 of 8

Thread: Best way for a graphicsitem to delete itself

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Best way for a graphicsitem to delete itself

    Actually, I think it is better to have the garbage collector in the scene, not the view, because you can have many views for the same items and it could get messy.

  2. #2
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Best way for a graphicsitem to delete itself

    Just to clarify, the code I have does seem to work, (items delete themselves). The only concern I have is if I'm creating a race condition or something. I did have one random crash once and am concerned that it might have been caused by that.

    Garbage collector is an option too, or perhaps emitting a signal to get the scene to delete the item (queuedconnection of course).

  3. #3
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Best way for a graphicsitem to delete itself

    Quote Originally Posted by pherthyl View Post
    The only concern I have is if I'm creating a race condition or something. I did have one random crash once and am concerned that it might have been caused by that.
    yes, that is the reason.

    Garbage collector is an option too, or perhaps emitting a signal to get the scene to delete the item (queuedconnection of course).
    I just thought a garbage collector would be more elegant... Queued connections are designed more for inter-thread communications. But I guess they could work... If not, you can always use postEvent.

  4. #4
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Best way for a graphicsitem to delete itself

    Thanks. I'll give the garbage collector a try.

  5. #5
    Join Date
    Jan 2006
    Posts
    371
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Best way for a graphicsitem to delete itself

    How about QObject::deleteLater() ...?

  6. #6
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Best way for a graphicsitem to delete itself

    Bingo. Thanks elcuco, I vaguely remembered such a function existing, but couldn't find it anymore.

Similar Threads

  1. Delete dialog
    By Krish_ng in forum Qt Programming
    Replies: 3
    Last Post: 9th August 2007, 12:42
  2. Deleting from TreeWidget... Memoryleak
    By VireX in forum Qt Programming
    Replies: 5
    Last Post: 1st June 2007, 21:33
  3. c++, placement delete upon exception
    By stinos in forum General Programming
    Replies: 6
    Last Post: 31st October 2006, 15:38
  4. Delete all members in a QGraphicsItemGroup
    By vmferreira in forum Qt Programming
    Replies: 3
    Last Post: 17th August 2006, 18:47
  5. QListWidget + Delete Key
    By bpetty in forum Newbie
    Replies: 5
    Last Post: 16th August 2006, 20:38

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
  •  
Qt is a trademark of The Qt Company.