If I have this code in a QGraphicsRectItem class:
Private:
@
QGraphicsRectItem *item;
@
Constructor:
@
item = new QGraphicsRectItem();
@
mousePressEvent:
@
this->addItem(item);
@
mouseReleaseEvent:
@
this->removeItem(item)
@
Do I must delete the item in the destructor, because the item is not a child of the scene ( this->removeItem(item) )??
Destructor:
@
delete item;
@
[quote author="cincirin" date="1337071681"][quote author="Mariø™" date="1337040692"]Thanks, you solved my doubt.
[quote author="MuldeR" date="1337039636"]I think you can design the constructor of your "Item" class as you like. If you never want to set a parent for "Item" objects, then you don't need to have the "parent" parameter in your constructor, of course. You can't change the constructor of QGraphicsItem, because it's a pre-defined class from Qt. But, as the definition of QGraphicsItem has a default value for the "parent" parameter, you don't need to have QGraphicsItem in initialization list of your Item constructor. The QGraphicsItem constructor will simply be called with a NULL parent.[/quote]
[/quote]
Note that if parent is 0, you need to manually add item to scene ( QGraphicsScene::addItem() ), and of course item will be top level.[/quote]