[PyQt] Python callback in SIP

Phil Thompson phil at riverbankcomputing.com
Fri Jun 12 15:14:32 BST 2009


On Fri, 12 Jun 2009 16:03:47 +0200, MD <marco.dinacci at gmail.com> wrote:
> Hi,
> 
>> To get hold of the Python object that wraps param use
>> sipConvertFromType().
>> You will need to read the section in the docs about accessing the API
>> when
>> embedding.
> 
> I'm stuck again, I have this code now in a sip file:
> 
> class A;
> class B : A {
> public:
>     B();
>     void foo(Bar &b) ;
> %MethodCode
> PyObject *obj = sipConvertFromType(sipCpp, sipType_B, NULL);
> PyObject *pyBar = sipConvertFromType(*b, sipType_Bar);
> PyObject *result =
> PyObject_CallMethodObjArgs(obj,PyString_FromString("foo"), pyBar,
> NULL);
> %End
> }
> 
> The result is:
> 
> _test.sip: In function 'PyObject* meth_B_foo(PyObject*, PyObject*)':
> _test.sip:41: error: 'sipType_B was not declared in this scope
> _test.sip:41: error: 'sipConvertFromType' was not declared in this scope
> _test.sip:42: error: 'b' was not declared in this scope
> _test.sip:42: error: 'sipType_Bar' was not declared in this scope
> error: command 'i686-unknown-linux-gnu-gcc' failed with exit status 1
> 
> I tried also in other ways, for instance by calling a global function
> from within the %MethodCode% directive but I had other problems.
> 
> I guess I'm not using the right approach though I don't see any other
> way, any help ?

So why are you now using .sip files? I though you were embedding in a C++
application, not generating a Python module.

Phil


More information about the PyQt mailing list