[PyQt] Embedded PyQt send signal to Qt

Phil Thompson phil at riverbankcomputing.com
Fri Jul 22 16:40:36 BST 2011


On Fri, 22 Jul 2011 23:08:51 +0800, zhang jian <zhangmdev at gmail.com>
wrote:
> I can retrieve the PyQt widget via Python C API, but it is a PyObject*,
so
> how to convert PyObject* to a QObject* ? Once I have the QObject*, the
rest
> should be easy in C++.
> 
> zhang

http://www.riverbankcomputing.com/static/Docs/sip4/c_api.html#sipConvertToType

You will also need to read...

http://www.riverbankcomputing.com/static/Docs/sip4/embedding.html

Phil

> On Fri, Jul 22, 2011 at 5:21 PM, Phil Thompson
> <phil at riverbankcomputing.com>wrote:
> 
>> On Tue, 19 Jul 2011 04:26:52 +0800, zhang jian <zhangmdev at gmail.com>
>> wrote:
>> > Hi,
>> >
>> > I have a question about embedded PyQt inside a Qt (C++) app. For now
I
>> have
>> > an app totally written in PyQt, then I want to embed it inside a Qt
app
>> > written in C++. I have no problem putting PyQt ui stuff inside a Qt
>> Widget.
>> > I can call stuff in PyQt from Qt using PyObject_CallMethod(), but I
>> don't
>> > know how to send signal from PyQt to Qt. I already have the PyObject*
>> > of
>> > the
>> > PyQt widget when I create the instance by PyObject_CallObject(). I
try
>> to
>> > connect((QObject*)some_instance, SIGNAL("some_signal"), this,
>> > SLOT(some_slot)), but no luck. I'd like to know if that is possible
to
>> > connect a signal in PyQt to a slot in Qt? If it is, how?
>>
>> Assuming you are doing the connection from C++, and assuming that the
>> signal is defined in Python using @pyqtSignal, then once you have a
>> pointer
>> to the underlying C++ QObject then just use the normal
QObject::connect()
>> call. Pass whatever you defined the signal to be using @pyqtSignal to
>> your
>> SIGNAL() call in C++.
>>
>> Phil
>>


More information about the PyQt mailing list