[PyQt] Python callback in SIP

Phil Thompson phil at riverbankcomputing.com
Mon Jun 15 11:22:56 BST 2009

On Mon, 15 Jun 2009 12:05:16 +0200, MD <marco.dinacci at gmail.com> wrote:
> Hi,
>> No you don't. SIP does all of that for you - otherwise it would be
>> useless as a C++ wrapper generator. Just provide a .sip file for your A
>> class and you shouldn't need any %MethodCode.
> I tried to provide a sip file for A but if I subclass it in Python I
> get a TypeError, A cannot be instantiated or sub-classed, which is why
> I'm now subclassing A in C++.

Then there is a problem with your .sip file for A.

> And in B, I cant' understand how that can work without some manual
> code, sorry. How does SIP understand that the method I want to call is
> the Python one and not the C++ one ?

It will call the nearest in the class hierachy - which will be the Python
one. If you want to call another implementation in the hierachy then
provide an explicit scope (eg. A.foo(self)).

> In my B class I have to override the foo method declared virtual in A;
> In my Python class I extend from B and I "override" again foo. Are you
> saying that SIP will call the foo method on the python class ? How ?
> I just made a test, and the Python method is never called.

Like I said, you seem to have problems in your .sip files.


More information about the PyQt mailing list