[PyQt] Signal/slot bug when doing multiple connects and Qt::UniqueConnection

Giuseppe Corbelli giuseppe.corbelli at copanitalia.com
Mon Apr 28 08:26:45 BST 2014


Hi all
I've run into an "interesting" side effect, admittedly misusing the 
signal-slot mechanism. Basically I'm doing multiple connections using the 
Qt::UniqueConnection parameter. As expected the slot is run always a single 
time, but there's something weird going on in the background. The receivers() 
method returns increasing numbers and this little example will kill the CPU in 
a few iteractions.

PyQt 4.10.3
Qt 4.8.5
Debian Kernel 3.3.5



#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys
import logging
import datetime

from PyQt4 import QtCore

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger('blah')

class CApp(QtCore.QCoreApplication):
     mysignal = QtCore.pyqtSignal()

     def emit_signal(self):
         for i in xrange(0, 1000):
             self.mysignal.connect(self.myslot, QtCore.Qt.UniqueConnection)
         logger.info("{} Preemit receivers {}".format(datetime.datetime.now(), 
self.receivers(self.mysignal.signal)))
         self.mysignal.emit()
         logger.info("{} Postemit".format(datetime.datetime.now()))

     def myslot(self):
         pass


app = CApp(sys.argv)
t = QtCore.QTimer()
t.timeout.connect(app.emit_signal)
t.start(500)

sys.exit(app.exec_())

-- 
             Giuseppe Corbelli
WASP Software Engineer, Copan Italia S.p.A
Phone: +390303666318  Fax: +390302659932
E-mail: giuseppe.corbelli at copanitalia.com


More information about the PyQt mailing list