[PyQt] bug or expected?

Phil Thompson phil at riverbankcomputing.com
Tue Jan 10 17:09:07 GMT 2017


On 27 Dec 2016, at 8:24 pm, oliver <oliver.schoenborn at gmail.com> wrote:
> 
> from PyQt5.QtCore import QObject, pyqtSlot, Qt, pyqtSignal
> 
> class MyObj(QObject):
>     sig_test = pyqtSignal()
> 
> class Listener(QObject):
>     @pyqtSlot()
>     def meth(self):
>         pass
> 
>     # @pyqtSlot()
>     def meth2(self):
>         pass
> 
> obj = MyObj()
> obs = Listener()
> 
> def test_no_connections(slot):
>     assert obj.receivers(obj.sig_test) == 0
> 
>     obj.sig_test.connect(slot, Qt.UniqueConnection)
>     assert obj.receivers(obj.sig_test) == 1
> 
>     obj.sig_test.disconnect(slot)
>     assert obj.receivers(obj.sig_test) == 0
> 
> test_no_connections(obs.meth)
> test_no_connections(obs.meth)
> 
> test_no_connections(obs.meth2)
> test_no_connections(obs.meth2)  # FAILS 
> 
> Last line fails because meth2 was not decorated with pyqtSlot. Is this expected or a bug?

It's only happening because you don't have an event loop (which is not the usual circumstance). However I can change things so that it will work in this case.

> Related to this, the exception on a unique connection is completely different if the method is decorated. Using the same code as above (but without the test_no_connections stuff): 
> 
> def test_unique_connection(slot, str_exc):
>     obj.sig_test.connect(slot, Qt.UniqueConnection)
>     try:
>         obj.sig_test.connect(slot, Qt.UniqueConnection)
>     except TypeError as exc:
>         assert str(exc) == str_exc
> 
> test_unique_connection(obs.meth, 'connect() failed between MyObj.sig_test[] and meth()')
> test_unique_connection(obs.meth2, 'connection is not unique')
> 
> Shouldn't both produce an exception that says 'connection is not unique'?

Ideally but the first one is from Qt and the second (more useful one) is from PyQt.

Phil



More information about the PyQt mailing list