[PyQt] QMetaObject.invokeMethod missing

David Boddie david at boddie.org.uk
Mon Apr 16 20:26:08 BST 2007


On Wednesday 11 April 2007 21:07:25 +0200, Henning Schröder wrote:

> I have Python embedded in a C++ application and I want to call its
> signals and slots without creating an extra wrapper with SIP.

This should be possible with PyQt 4.2.

> Therefore I need QMetaObject.invokeMethod (or perhaps better
> QObject.qt_metacall I guess).

The caller (in C++) needs QMetaObject::invokeMethod(). You only need this
in Python if you want to call methods on arbitrary unwrapped instances of
QObject subclasses.

> I got the idea from Kross (http://kross.dipe.org/index.html) and I got
> nearly everything implemented in PyQt4, see
> http://henning.cco-ev.de/mikro_py.txt if you like.
>
> Is there any special reason why this method is not wrapped? It looks
> not as easy as setText() for example but not impossible.

It is wrapped behind the scenes, but just not exposed to Python. You would
need to have a compelling reason to use it, and a good idea about how it
should work, to justify getting it added to the API exposed by PyQt.

The good news is that the support for Qt Designer recently added to PyQt
should help you do what you want.

You can declare properties from within Python by using the pyqtProperty()
function in QtCore to declare a getter, a setter and a property type for each
property. Slots are declared by applying the QtCore.pyqtSignature decorator
to methods. Signals are declared in a __pyqtSignals__ sequence that you add
to the class you want to export to C++; traditionally, PyQt applications
don't need to declare signals in advance, but C++ applications like to be
able to query classes for their signals.

A simple example to look at is the Analog Clock plugin example in the PyQt4
source distribution (examples/designer/plugins/widgets/analogclock.py).
This provides a custom property, whose setter method is also a slot, and two
signals.

David



More information about the PyQt mailing list