[PyKDE] C++ conversion to python, using sip

Phil Thompson phil at riverbankcomputing.co.uk
Sat Jun 28 16:18:01 BST 2003


On Saturday 28 June 2003 3:32 am, Park joon cheol wrote:
> Error messages: A function with the same Python signature has already
> been defined
>
> C++ Code:
>
> Class foo
> {
> ...
>
>     bool            write (const QString  &section,
>                            const QString  &entry,
>                            int             value);
>
>     int             read  (const QString  &section,
>                            const QString  &entry,
>                            int             value);
>
>     bool            write (const QString  &section,
>                            const QString  &entry,
>                            double          value);
>
>     double          read  (const QString  &section,
>                            const QString  &entry,
>                            double          value);
>
>
> ...
> }
>
>
>
>
> sip code:
>
> class foo
> {
> ...
>
>     bool            write (const QString&,
>                            const QString&,
>                            int);
>
>     int             read  (const QString&,
>                            const QString&,
>                            int             );
>
>     bool            write (const QString&,
>                            const QString&,
>                            double          );
>
>     double          read  (const QString&,
>                            const QString&,
>                            double          );
>
>
> ...
> }
>
>
> Is it possible to conversion C++'s overloaded method in SIP?

Yes, but you have to tighten up the signature. The problem is that Python will 
normally automatically convert an int to a double and vice versa. The 
solution is to add /Constrained/ to the int parameters which means "match an 
int, and only an int" rather than "match an int and anything that can be 
converted to an int".

For example...

bool write (const QString &, const QString &, int /Constrained/);

Also check out the PyQt .sip files for more examples.

Phil




More information about the PyQt mailing list