[PyQt] a subclass for a c++ object

Phil Thompson phil at riverbankcomputing.com
Sat Jun 26 09:13:22 BST 2010


On Sat, 26 Jun 2010 00:17:36 -0400, Blaine Bell
<blaine.bell at schrodinger.com> wrote:
> When I subclass a c++ object which is wrapped in SIP, I have found that 
> I need to include all functions of that C++ object in the SIP interface 
> that are used from within that class (or any of its subclasses).  For 
> example, this one class I am using in python subclasses a class that 
> subclasses QAbstractProxyModel, and overrides the function 
> "Qt::ItemFlags flags(const QModelIndex &index) const;".  I do not use 
> this function at all in python, but it doesn't get called unless I 
> include it in the SIP interface.  Can someone explain what is happening 
> here?  I would think that if that class is being instantiated properly, 
> then inside C++ the interface should have all of the functions 
> implemented.  Is it possible I am not doing something right here?

SIP will generate a C++ reimplementation of flags() that works out if there
is a Python reimplementation and calls it if so.

If there is no Python version then it explicitly calls the most specific
C++ implementation that it knows about. It has to explicitly call it (i.e.
with an explicit scope) to avoid recursion. If you haven't told it about a
more specific version (because it doesn't appear in the corresponding .sip
file) then it can never be called.

Phil


More information about the PyQt mailing list