[PyQt] Python callback in SIP
Phil Thompson
phil at riverbankcomputing.com
Fri Jun 12 11:31:43 BST 2009
On Fri, 12 Jun 2009 10:51:49 +0200, MD <marco.dinacci at gmail.com> wrote:
> Hi,
> I have the following situation where some C++ code should call a
> Python method:
>
> C++ class:
>
> class A {
> public:
> void foo(bar param&);
> };
>
> Python class:
>
> class PyA(module.A):
> def foo(bar):
> bar.doSomething()
>
> How do I model this situation in SIP ?
>
> My idea was to extend A in C++ and override its foo method in order to
> call the python method of PyA,
So long as foo() is virtual, which it isn't in your example.
> but to do this I need to pass the
> Python object to A (or maybe better just the foo method), something
> like this:
>
> class B: public A {
> public:
> B(PyObj *po): m_PyObj(po) {}
> void foo (bar param &) {
> sipCallMethod(...)
> }
> private:
> PyObj m_PyObj;
> }
>
> but how do I get the Python object ? and what is its type ? should I
> pass it directly from Python by calling a module method ? I would
> like to avoid this situation considering there will be plenty of
> python objects.
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.
Phil
More information about the PyQt
mailing list