durbrak
11th February 2008, 18:44
Hi guys,
I'm sort of confused right now. Let's say I have created a QGraphicsLineItem(), which will eventually have children (all sorts of graphics items, doesn't really matter). Now I want to explicitly delete my object:
QGraphicsLineItem *line = new QGraphicsLineItem(scene);
//...
QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(line);
//...
delete line;
line = 0;
Now the part I don't get is that in the Qt sources the destructor of QGraphicsLineItem is empty:
QGraphicsLineItem::~QGraphicsLineItem()
{
}
QGraphicsLineItem is, of course, a sub-class of QGraphicsItem, which has the destructor defined with code to delete all its children.
So, how is it, that if I delete my QGraphicsLineItem that it will also delete all its children (i.e. *label)? The base class destructor QGraphicsItem::~QGraphicsItem() is declared as virtual, thus a destructor wouldn't be needed for QGraphicsLineItem, right? And by declaring an own destructor for QGraphicsLineItem which is empty, the base class destructor doesn't get called, right?
Or am I missing something here?
Thanks.
I'm sort of confused right now. Let's say I have created a QGraphicsLineItem(), which will eventually have children (all sorts of graphics items, doesn't really matter). Now I want to explicitly delete my object:
QGraphicsLineItem *line = new QGraphicsLineItem(scene);
//...
QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(line);
//...
delete line;
line = 0;
Now the part I don't get is that in the Qt sources the destructor of QGraphicsLineItem is empty:
QGraphicsLineItem::~QGraphicsLineItem()
{
}
QGraphicsLineItem is, of course, a sub-class of QGraphicsItem, which has the destructor defined with code to delete all its children.
So, how is it, that if I delete my QGraphicsLineItem that it will also delete all its children (i.e. *label)? The base class destructor QGraphicsItem::~QGraphicsItem() is declared as virtual, thus a destructor wouldn't be needed for QGraphicsLineItem, right? And by declaring an own destructor for QGraphicsLineItem which is empty, the base class destructor doesn't get called, right?
Or am I missing something here?
Thanks.