[PyQt] %ConvertToSubClassCode across modules

Gerard Vermeulen gav451 at gmail.com
Sat May 31 10:24:27 BST 2008


On Fri, 30 May 2008 23:41:57 +0100
Phil Thompson <phil at riverbankcomputing.com> wrote:

[ snip ]
> > 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().
> 
You can also rely on the RTTI provided by the compiler (seems to not
always work on Windows). PyQwt has code like:

%If (CXX_DYNAMIC_CAST)
%ConvertToSubClassCode
    // Walk the inheritance tree depth first in alphabetical order
    // This code is for Qwt4 and Qwt5
#ifdef sipClass_QwtArrayData
    if (dynamic_cast<const QwtArrayData *>(sipCpp))
        sipClass = sipClass_QwtArrayData;
    else
#endif
#ifdef sipClass_QwtDoublePointData
    if (dynamic_cast<const QwtDoublePointData *>(sipCpp))
        sipClass = sipClass_QwtDoublePointData;
    else
#endif
#ifdef sipClass_QwtPolygonFData
    if (dynamic_cast<const QwtPolygonFData *>(sipCpp))
        sipClass = sipClass_QwtPolygonFData;
    else
#endif
#ifdef sipClass_QwtData
    if (dynamic_cast<const QwtData *>(sipCpp))
        sipClass = sipClass_QwtData;
    else
#endif
        sipClass = 0;
%End
%End

Gerard



More information about the PyQt mailing list