[PyKDE] convertSubClass() -- I introduced a bug :-(

Phil Thompson phil at riverbankcomputing.co.uk
Mon Apr 12 10:39:01 BST 2004


On Monday 12 April 2004 4:11 am, dacut at neolinear.com wrote:
> Phil Thompson wrote:
> > Why would overlapping converters (ie. the same class is handled in more
> > than one converter) ever be required?
>
> It shouldn't... but the problem (can) manifest itself due to is-a
> relationships.
>
> As an example, let's say that base class A has subclasses B, C, and D.  The
> SIP subclass converter for A knows how to downcast to B, C, and D.

Don't talk about *the* subclass converter for A, there can be any number of 
them. For example, the qt, qtcanvas, qtext, qtgl, qtnetwork, qtsql and 
qttable all provide converters for QObject.

> Now I create class E, a subclass of B.  Because any E instance is also a B
> instance, the subclass converter for A would downcast this to B -- Python
> would not have any of E's features available.

Which is why you don't write overlapping convertors.

> AFAICT, this problem does not manifest itself in Qt or PyQt -- QObjects
> have their own metaclass information, and QCanvasItem's subclass converter
> will return NULL for unknown subclasses.  I don't have the source right
> now, though, so I'll have to double-check.
>
> This aliasing would happen, though, for any converter which relies on
> dynamic_cast<>() (and some other kits which have their own RTTI).

The source of the type information is irrelevant. I agree that using 
dynamic_cast<>() would potentially mean you had overlapping converters - but 
that's just a bug in the converter.

Phil




More information about the PyQt mailing list