[Qt-interest] QGraphicsScene::addItem item has already been added to this scene Error

Sean Harmer sean.harmer at maps-technology.com
Fri Jun 18 15:26:35 CEST 2010


Hi,

Please respond to the list. Not to me personally.

On Friday 18 June 2010 13:50:23 you wrote:
> So if the parent is already in the scene iddon't need to set parent
> for the child objects?

No. What I said was that if you create a QGraphicsItem with a parent that is 
already in the scene, then you do not need to add the new item to the scene.

For example:

// Create a parent item and add it to the scene
QGraphicsRectItem* parentRect = new QGraphicsRectItem;
myScene->addItem( parentRect );

// Create a child of parentRect. No need to explicitly add
// it to the scene since the parent has already been added
// and the child item inherits this
QGraphicsRectItem* childRect = new QGraphicsRectItem( parentRect );

// myScene->addItem( childRect ) would trigger the error you saw

Sean



More information about the Qt-interest-old mailing list