Priority: P2: Important
Affects Version/s: 4.7.2
Fix Version/s: None
Component/s: Widgets: GraphicsView
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:
QGraphicsItem* child = scene1.addRect(0, 0, 50, 50);
QGraphicsItem* parent = scene2.addRect(0, 0, 100, 100);
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) !