Results 1 to 5 of 5

Thread: QT 4.6.3 bug? QGraphicsItem receives paint even when removed from scene?!

  1. #1
    Join Date
    May 2009
    Posts
    63
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question QT 4.6.3 bug? QGraphicsItem receives paint even when removed from scene?!

    Hi,

    I`ve got a situation that I`ve been trying to fix for a few days:

    I have a scene that contains a single object derived from QGraphicsItem.
    If I remove the object from the scene (calling QGraphicsScene::removeItem()) and then delete the pointer to the object, my program crashes later when the QGraphicsScene repaints.

    Basically, it turns out the item I removed from the scene is still in the Qt's internal BSP tree representation of the scene. This happens even though a call to QGraphicsScene::items().count() (after deleting the item) returns 0.

    - QGraphicsScene derefences the pointer to the object that has been removed and deleted.

    If I don't delete the object (i.e. free the memory allocated to it) then QT still renders the object even though the scene is empty (QGraphicsScene::items().count() returns 0) !!!

    Does anyone have any ideas what could cause this? Is QT performing reference counting or something.

    Is it necessary to call another function to invalidate QT's BSP tree?

    Sorry - there is too much code in the project to paste.

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QT 4.6.3 bug? QGraphicsItem receives paint even when removed from scene?!

    Can you duplicate the problem in a simple implementation? A QGraphicsView looking at a QGraphicsScene while adding and removing a single QGraphicsItem, for example.

    It certainly could be a bug in Qt. But I'd check your own code first, looking for dangling references or multiple addItem() calls that may be part of the problem. Running through a tool like valgrind (under Linux) might be instructive.

    Also, what happens if you have more than one item, and remove the second-to-last item from the scene? Same behavior? If it's only related to the last item being removed, you could stuff a small, invisible "dummy" item in the scene as a workaround.

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

    jonks (30th August 2010)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QT 4.6.3 bug? QGraphicsItem receives paint even when removed from scene?!

    I'd check whether you are not removing an object from the scene (and deleting it) upon receiving a signal carrying the item somewhere within its arguments.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    jonks (30th August 2010)

  6. #4
    Join Date
    May 2009
    Posts
    63
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Smile Solved: QT 4.6.3 bug? QGraphicsItem receives paint even when removed from scene?!

    The bug only happens when I resize an item and make it smaller than the original size.

    I created a small prog to reproduce it and while in the Qt code in the call stack I found a check for changedSignalIndex.
    Googled for that, and came across this post

    I had neglected to call
    Qt Code:
    1. QGraphicsItem::prepareGeometryChange()
    To copy to clipboard, switch view to plain text mode 
    when changing the item's bounding rect.
    Failing to call this results in a pointer to my object remaining in the BSP tree.

    Thank goodness for opensource code! I don't think I would have discovered the necessity to call prepareGeometryChange by reading the docs.

  7. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Solved: QT 4.6.3 bug? QGraphicsItem receives paint even when removed from scene?!

    Quote Originally Posted by jonks View Post
    I don't think I would have discovered the necessity to call prepareGeometryChange by reading the docs.
    Right, there surely is no sentence in the docs such as this one:
    Quote Originally Posted by QGraphicsItem docs
    If you want to change an item's geometry in any way, you must first call prepareGeometryChange() to allow QGraphicsScene to update its bookkeeping
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QGraphicsItem .. Scene .. View question?
    By DirtyBrush in forum Qt Programming
    Replies: 21
    Last Post: 19th October 2010, 10:12
  2. Overload QGraphicsItem Move in Scene
    By D Cell in forum Newbie
    Replies: 2
    Last Post: 16th March 2010, 06:14
  3. Can I copy a QGraphicsItem on my scene?
    By JesperWe in forum Qt Programming
    Replies: 3
    Last Post: 12th February 2010, 22:21
  4. Paint QGraphicsItem problem
    By dreamer in forum Qt Programming
    Replies: 3
    Last Post: 23rd June 2008, 19:18
  5. Deleting a scene from QGraphicsItem mouseEvent
    By JonathanForQT4 in forum Qt Programming
    Replies: 5
    Last Post: 10th April 2007, 12:27

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.