[PyQt] signal/slot vs Qt.UniqueConnection ?
Hans-Peter Jansen
hpj at urpla.net
Thu Apr 7 14:37:29 BST 2011
On Thursday 07 April 2011, 12:49:43 Zoltan Szalai wrote:
> Hi,
>
> I'm quite sure I'm missing something fundamental here but I can't get
> QObject.connect to work as expected when using Qt.UniqueConnection as
> a connection type.
> I attached some code that demonstrates my problem. I would expect
> that the slot is called only once.
Hmm, it seems to depend on the type of slot argument, and is probably
something, that Phil hasn't expected.
It seems to work this way:
from PyQt4.QtCore import *
class A(QObject):
signal = pyqtSignal()
def __init__(self, parent=None):
super(A, self).__init__(parent)
def connectNotify(self, signal):
print 'connectNotify:', signal
@pyqtSlot()
def slot(self):
print 'slot called'
app = QCoreApplication([])
a = A()
print "1:", a.signal.connect(a.slot, Qt.UniqueConnection)
print "2:", a.signal.connect(a.slot, Qt.UniqueConnection)
a.signal.emit()
Now, an exception is thrown in the second attempt to connect:
Traceback (most recent call last):
File "uniqueconnection_test.py", line 19, in <module>
print "2:", a.signal.connect(a.slot, Qt.UniqueConnection)
TypeError: connect() failed between A.signal[] and slot()
Another strange effect is, that in your case with a slot as a function
something connects to the destroyed(QObject*) signal, but not in mine.
Pete
More information about the PyQt
mailing list