[PyQt] pyqtSlot

oliver oliver.schoenborn at gmail.com
Thu Aug 25 12:48:27 BST 2016


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?

Oliver
Open Source contributions: PyPubSub <http://pubsub.sf.net/>, nose2pytest
<https://github.com/schollii/nose2pytest>, Lua-iCxx
<http://lua-icxx.sf.net/>, iof <http://iof.sf.net/>
StackOverflow <http://stackoverflow.com/users/869951/schollii> contributions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20160825/c41ad034/attachment.html>


More information about the PyQt mailing list