Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-18616

QGraphicsItem::setParentItem() fails with a wrong assertion when parent is in a different scene

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 4.7.2
    • Widgets: GraphicsView
    • None

    Description

      Calling QGraphicsItem::setParentItem() on a item that resides in a different scene than the new parent crashes the application in debug mode due to an invalid assertion.
      Here is a sample code that can reproduce the problem:

      QGraphicsScene scene1;
      QGraphicsScene scene2;
      QGraphicsItem* child = scene1.addRect(0, 0, 50, 50);
      QGraphicsItem* parent = scene2.addRect(0, 0, 100, 100);

      child->setParentItem(parent);

      I have debugged the code and I think to have found where the problem comes from. Actually, in "QGraphicsItem.cpp" in the method "QGraphicsItemPrivate::setParentItemHelper()" at line 1201 (if (parent = newParent)), the new parent item is assigned to the "parent" member of the child item prior to add this one to the new parent's scene. However, in the process of adding the child item to the new parent item's scene, the item is firstly removed from the old scene where an assertion check is made between this old scene and the scene of the parent item which are obviously not the same (QGraphicsScene.cpp in QGraphicsScenePrivate::removeItemHelper() method at line 620) !

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            andrhans Andreas Aardal Hanssen
            sgobance Stephane Gobance
            Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes