[PyQt] Python callback in SIP

MD marco.dinacci at gmail.com
Fri Jun 12 09:51:49 BST 2009


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, 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.

Thanks
MD


More information about the PyQt mailing list