[PyKDE] sip & overloaded methods

Phil Thompson phil at river-bank.demon.co.uk
Sat Apr 28 03:01:01 BST 2001


Greg Green wrote:
> 
> Hello,
> 
> I am trying to use the QWMatrix class in Qt. It has several map
> methods taking different arguments. Looking at the source, all of the
> methods are defined, but it appears in practice that only the
> map(int, int, int*, int*) method is called which is unfortunate as i
> have double values that are getting rounded off.
> 
> Looking at siplib, I don't see how these overloaded methods could be
> called. I don't see any magic methods to dispatch on the correct
> method based on the arguments. It appears that the names must be
> changed on these overloaded methods so that the correct ones can be
> called.
> 
> Or am I missing something?

This is a long standing bug - not resolved because I haven't come to a
conclusion about what the most "correct" fix is.

The problem is that Python can convert between numeric types quite
happily, so it can't distinguish between types as well as C++ can. It
knows that it can convert doubles to ints so it converts the doubles to
ints and calls the int version of map rather than not converting the
doubles and calling the double version of map.

Actually, I know the proper answer - sip should realise the potential
amiguity and apply more intelligent tests on the arguments. In the
meantime (if you are happy to regenerate the C++ code from the .sip
files) the easiest thing to do is to use something like
/PyName=map_double/ to the map(double,double...) entry in qwmatrix.sip.
If you want to pass floating point values you call
QWmatrix.map_double(), call QWMatrix.map() if you want to pass ints.

Phil




More information about the PyQt mailing list