[PyQt] [PyQt 4.5] Crash emit signal

Alexandr N Zamaraev tonal at promsoft.ru
Mon Apr 13 05:31:55 BST 2009


Os Windows Vista Home Ru + sp1
g++ (GCC) 3.4.5 (mingw-vista special r3)
Qt 4.5 (self build)
sip-4.8-snapshot-20090409 (self build)
PyQt-win-gpl-4.5-snapshot-20090411.zip (self build)


P.S. We found this in the code code:
def connectWidget(self, widget):
    widget.signalA.connect(self.signalA)
    widget.signalB.connect(self.signalB)
    widget.signalC.connect(self.signalC)

Maybe it makes sense to change the connect as follows:
class pyqtSignal (...):
   def connect(self, arg):
     if hasattr(arg, self.name):
       arg = getattr(arg, self.name):
     elif hasattr (arg, '__class__') and hasattr (arg, '_%s__%s' % 
(arg.__class__.__name__, self.name):
       #find private atts with name '__on_signame'
       arg = getattr(arg, '_%s__on_%s' % (arg.__class__.__name__, self.name)
     #remaining processing
-------------- next part --------------
import sys
from PyQt4 import QtCore

def redirect_signal(src, dst, sig):
  getattr(src, sig).connect(getattr(src, sig))

class A(QtCore.QObject):
  signal = QtCore.pyqtSignal()

  def f(self):
    self.signal.emit()

class B(QtCore.QObject):
  signal = QtCore.pyqtSignal()

  def __init__(self, arg):
    super(B, self).__init__()
    redirect_signal(arg, self, 'signal')
    #arg.signal.connect(self.signal)

class C(QtCore.QObject):
  def __init__(self, arg):
    super(C, self).__init__()
    arg.signal.connect(self.__do)

  def __do(self):
    print 'Hi'

def main():
  app = QtCore.QCoreApplication(sys.argv)
  a = A()
  b = B(a)
  c = C(b)
  a.f()

if __name__ == '__main__':
  main()


More information about the PyQt mailing list