[PyQt] bug or expected?

oliver oliver.schoenborn at gmail.com
Tue Dec 27 20:24:17 GMT 2016


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?

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'?
-- 
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/20161227/06b4db7a/attachment.html>


More information about the PyQt mailing list