[PyKDE] Re: How can I use SIP to wrap STL

Jim Bublitz jbublitz at nwinternet.com
Fri Apr 19 18:21:34 BST 2002


On 17-Apr-02 ejoy <ejoy at peoplemail.com.cn> wrote:
> I fix the Makefile and the compile progress seems good:

<snip>

> but somehow the %ConvertFromType section seems not executed when
> I lunch test.py.
 
> I can not figure out where is the fault.So I pack all the code in
> attachment and hope someone can help me out.

Sorry I couldn't respond sooner.

As I pointed out in my original response, if you want to pass a
parameter by reference ('d' in your example) like this:

    a.foo(s,d)

and use the modified value of 'd' in Python, you will either
need to write %MemberCode for 'foo' so that 'd' is the return value
of 'foo' in Python:

    d = a.foo(s, d)  [1]

or rewrite 'foo' to return 'd' instead:

    d = a.foo(s)  [2]

For [1] you will have to insert code in the sip file to have 'foo'
return 'd'(grep PyQt or PyKDE2 for %MemberCode and look at the
examples there - even if the C++ 'foo' returns 'void', you can cause
it to return whatever type 'd' is to Python). For [2], sip will
generate the code automatically but you'll have to rewrite your C++
to return 'd' instead of void.

You're correct that in [1], the %ConvertFromType code will never
execute. [2] is much easier if you control the C++ code you're
writing bindings for. 


Jim





More information about the PyQt mailing list