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

    • Type: Bug
    • Status: Open
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: 4.7.2
    • Fix Version/s: None
    • Component/s: Widgets: GraphicsView
    • Labels:
      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

            Assignee:
            andrhans Andreas Aardal Hanssen
            Reporter:
            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