Destructor overriding
-
I examined the [url='http://qt-project.org/doc/qt-4.8/graphicsview-diagramscene.html']Diagram Scene Example[/url] and faced this code:
[code]void DiagramItem::removeArrows()
{
foreach (Arrow *arrow, arrows) {
arrow->startItem()->removeArrow(arrow);
arrow->endItem()->removeArrow(arrow);
scene()->removeItem(arrow);
delete arrow;
}
}[/code]Where Arrow is:
[CODE]
class Arrow : public QGraphicsLineItem
[/CODE]My question is, whether it is adequate to implement DiagramItem::removeArrows() method that way instead of overriding the Arrow's destructor:
[CODE]
Arrow::~Arrow()
{
startItem()->removeArrow(this);
endItem()->removeArrow(this);
}
[/CODE]Then DiagramItem::removeArrows() would look like:
[CODE]void DiagramItem::removeArrows()
{
foreach (Arrow *arrow, arrows) {
scene()->removeItem(arrow);
delete arrow;
}
}[/CODE] -
well the only thing that wouldn't work in that case (just by taking a glimpse at the code you wrote not the example) would be the scene()->removeItem(arrow) which should be in the removeArrows function
-
Oh, yes, this is a mistake. "scene()->removeItem(aarow)" is not needed in destructor, fixed that. But elsewise?