[PyKDE] Connecting PYSIGNALS to C++ slots

Phil Thompson phil at riverbankcomputing.co.uk
Mon Jul 7 13:30:01 BST 2003


On Sunday 06 July 2003 2:07 pm, Rob Knapp wrote:
> I am writting a C++ wrapper for some python QT objects.  As a result,
> I need to recieve the PYSIGNALS from the python object and retransmit
> them so my container binary can connect to them. [This is a double post
> (kind of), I posted the same question on thursday (7/3/2003), but I've
> tried a bunch of new things so I thought I would include those as well.]

So you are writing a C++ wrapper for a Python class that itself is derived 
from a PyQt class that wraps a C++ Qt class???

If so, I would re-visit the architecture.

> From the documentation it looks like I need to use sipConnectRX (please
> correct me if this is wrong).
>
> This is the code that I'm trying to use:
>
> PyObject * sipThisObject;
> sipThisObject = sipGetThisWrapper( this, qtQWidget);
> sipConnectRx(objPyWidget, "SomePythonSignal", sipThisObject,
> "slot_OnSomePythonSignal")

sipGetThisWrapper() returns a sipThisType *, not a PyObject * (although you 
can cast between the two). This is the value of "sipThis" which is stashed in 
a class instance's dictionary. It is the class instance that needs to be 
passed to sipConnectRx(), ie. sipThisObject -> sipSelf.

> qtQWidget is the pyobject representing the class that I get from the qt
> module.

ie. sipClass_QWidget?

> objPyWidget is a member variable in my class which is an instance of my
> pyqt widget.
>
> I've tried the following variations with no luck, sipThisObject is always
> null:
> haveing my wrapper inherit from sipQWidget
> trying to get a wrapper for QObject
> casting the this pointer to a sipQWidget pointer.

If sipGetThisWrapper() returns NULL then the C++ instances does not have a 
corresponding Python instance object. Something along the following lines is 
needed...

self = sipMapCppToSelf(this,sipClass_QWidget);
sipConnectRx(objPyWidget,"9SomePythonSignal",self,SLOT(slot_OnSomePythonSignal()));
Py_DECREF(self);

Phil




More information about the PyQt mailing list