[PyQt] How to use sipAPIDef::api_get_pyobject and sipQtAPI::qt_connect

Phil Thompson phil at riverbankcomputing.com
Sat Nov 26 17:29:46 GMT 2011


On Sat, 26 Nov 2011 10:37:12 -0600, Jack Cosgrove <jackcosgrove at gmail.com>
wrote:
> Hi,
> 
> I'm trying to connect a C++ signal to a Python slot. What is the best
> way to do this?

Two ways...

1. Make the receiver visible to C++ and use QObject::connect(), ie.
decorate the slot with pyqtSlot().

2. Make the transmitter visible to Python and PyObject_Call() the signal
object, ie. convert the transmitter to a Python object. Note that this will
only work if there are .sip bindings for the transmitter.

> My current approach is to use sipQtAPI::qt_connect, and to do this I
> need to apparently convert the C++ object to a PyObject using SIP. I do
> that using sipAPIDef::api_get_pyobject. However whenever I call this
> method using the appropriate sipType I get a segmentation fault.

qt_connect() is internal, don't use it. sipGetPyObject() doesn't do what
you think it does - sipConvertFromType() is probably what you want.

> I have included a small qmake project that replicates this behavior.
> Could someone look it over and offer advice on what I am doing wrong?

Phil


More information about the PyQt mailing list