[PyQt] pyqtSlot
Phil Thompson
phil at riverbankcomputing.com
Thu Aug 25 12:59:11 BST 2016
On 25 Aug 2016, at 12:48 pm, oliver <oliver.schoenborn at gmail.com> wrote:
>
> I read recently in an exchange between Florian and Phil that:
>
> The main purpose of pyqtSlot is to define a new entry in the QObject's QMetaObject, so you would normally only use it on a method. pyqtSlot doesn't check that the containing class is a QObject because it might be being used as a mixin. When the connection is made the receiver must be a QObject.
>
>
> In our code, we wrap slots so that we can customize error handling, so in a couple places we have code like this:
>
>
> def slot_fixer(qobject_method):
>
> def slot_wrapper():
>
> ...do stuff...
>
> qobject_method()
>
> return pyqtSlot()(slot_wrapper)
>
>
> class Foo(QObject):
>
> def qobject_method(self):
>
> ....
>
>
> slot_qobject_method = slot_fixer(qobject_method)
>
>
> I.e., the method wrapped is from a QObject-derived class, but what pyqtSlot "decorates" is a wrapper for this method. This seems to have been working fine in PyQt 5.3 and 5.5, were we just lucky? Is it safe in 5.7?
Inspect the QMetaObject to see if the slot is there as you would expect.
Phil
More information about the PyQt
mailing list