[PyQt] bug or expected?

oliver oliver.schoenborn at gmail.com
Wed Jan 11 17:19:43 GMT 2017


On Tue, 10 Jan 2017 at 12:09 Phil Thompson <phil at riverbankcomputing.com>
wrote:

> 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.
>

That would be great! Although it is not relevant in an app context, it is
in testing context (where we don't always exec an app instance).


> > 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
>
>
Good to know, thanks.
Oliver

-- 
Oliver
My StackOverflow contributions
My CodeProject articles
My Github projects
My SourceForget.net projects
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170111/087a2186/attachment.html>


More information about the PyQt mailing list