[Qt-interest] ~QAbstractGraphicsShapeItem() is not virtual

Robert Hairgrove evorgriahr at hispeed.ch
Fri Aug 28 19:00:35 CEST 2009


Scott Aron Bloom wrote:
> I filed it as a bug about 5 years ago... even though the compiler WILL
> do the right thing, it makes it self documenting that it is virtual.. 
> 
> The bug was denied :)  I requested it on the generated code from uic 3..
> 
> Scott
> 
>> Hi.
>> I am found that ~QAbstractGraphicsShapeItem() is not virtual and
>> some classes are inherits from it (QGraphicsEllipseItem,
>> QGraphicsPathItem, QGraphicsPolygonItem, QGraphicsRectItem, and
>> QGraphicsSimpleTextItem.)
>> Is this the bug?
> 
> Hi,
> 
> The destructor is declared as virtual in the base class
> (QGraphicsItem). It remains virtual in subclasses regardless of the
> missing virtual keyword.

That the base class' virtual destructor (and indeed, any virtual 
function) automatically makes the destructor or overriding function of 
the derived class virtual, even without the keyword, is a requirement of 
the C++ Standard. All compilers supported by Qt (today) are compliant in 
this respect, hence I can't see any reason to call it a bug. It is more 
a question of style whether to include "virtual" or not.



More information about the Qt-interest-old mailing list