[PyQt] SIP newbie question (%MethodCode oddity)

Phil Thompson phil at riverbankcomputing.co.uk
Thu Jan 10 12:00:30 GMT 2008

On Tuesday 08 January 2008, Jim Crowell wrote:
> Hi all,
> I'm fiddling with SIP 4.7.3 on XP for a non-Qt-related project. As a
> learning exercise I tried porting the Fraction example at
> <http://www.panix.com/~elflord/unix/siptute/> to SIP 4. Got it working
> to a first approximation, but there's a bit that puzzles me: sipCpp
> doesn't always get defined in %MethodCode blocks where it looks like it
> should.
> Here's the working .sip code for two methods:
> float __float__();
> %MethodCode
> 	sipRes = (double)sipCpp->numerator() / sipCpp->denominator();
> %End
> Fraction __add__( Fraction );
> %MethodCode
> 	sipRes = new Fraction(*a0 + *a1);
> %End
> i.e. in the latter case sipCpp is not defined, but that same
> self-as-c++-object pointer resides in a0. Can anyone tell me why?

It's an artifact of the way global operators (eg. operator+()) are 
implemented. I've fixed the documentation to describe the inconsistency.


More information about the PyQt mailing list