[PyQt] %ConvertToSubClassCode across modules

Phil Thompson phil at riverbankcomputing.com
Fri May 30 23:41:57 BST 2008


On Friday 30 May 2008 11:29:37 pm Kevin Watters wrote:
> In the docs for %ConvertToSubClassCode, there's a mention about class
>
> hierarchies over multiple modules:
> >> Note that if a class hierarchy extends over a number of modules then
> >> this directive should be used in each of those modules to handle the
> >> part of the hierarchy defined in that module. SIP will ensure that
> >> the different pieces of code are called in the right order to
> >> determine the most specific Python type to use.
>
> I've got this situation, but there's a small problem. Say MyObject is
> defined in the main module, and has %ConvertToSubClassCode. Then in a
> second module, I've got several objects that all inherit from MyObject.
> They are all leaf nodes in the class hierarchy, so there's no common
> base class in that other module to stick more %ConvertToSubClassCode
> into.

It doesn't matter - any one of them will do.

> Browsing through the PyQT sources, it looks like this case doesn't
> happen, and there's always a common base class. (Oddly there's those
> switch statements with hard coded integer constants checking against
> sipCpp->type()--are those automatically generated? Or is it just relying
> on the order classes are defined?)

type() is a method of QEvent.

> But what can I do about this? It'd be nice to avoid some kind of runtime
> RTTI list that the submodule appends to on startup, but if that's what
> I have to do, that's alright ;) Just thought I'd check here first for
> any ideas.

Your class (or your code) has to provide some form of RTTI. QEvent provides 
type(), QObject provides inherits().

Phil


More information about the PyQt mailing list