title: Python PyQt5 signals & slots
body: <p>I am having some trouble applying the new pyqt5 <a href="http://pyqt.sourceforge.net/Docs/PyQt5/signals_slots.html" rel="nofollow">signals and slots</a> into a script thats purpose is to test/invoke another problem I've been trying to solve, GUI freezing/crashing ... the aim is so that once these signals and slots are functioning correctly the GUI will not crash after +/- 30 seconds of runtime, and just continue on counting numbers until the end of time. I have provided a pyqt4 example although it would be great to have a pyqt5 solution. Thanks :)</p>
  
  <pre><code>from time import sleep
  import os
  from PyQt4 import QtCore, QtGui, uic
  from PyQt4.QtGui import * 
  import random
  import os
  import time
  
  
  class Cr(QtCore.QThread):
      def __init__(self):
          QtCore.QThread.__init__(self)
      def run(self):
  
          while True:
              rndInt = random.randint(1, 100000)
              timesleep = random.random()
              time.sleep(timesleep)
              for i in range(120):
                  self.emit(QtCore.SIGNAL('host_UP'), 'foo' + str(rndInt), i)
                  QtGui.QApplication.processEvents()
  
  
  class Main_Window(QWidget):
  
      def __init__(self, *args): 
          QWidget.__init__(self, *args)
          self.relativePath = os.path.dirname(sys.argv[0])
  
          self.Main_Window = uic.loadUi("Main_Window.ui", self)
          self.Main_Window.show()
          self.Main_Window.move(790, 300)
  
          self.GU = []
          ProgressThreads = self.printThreads
          self.details_label = []
          for i in range(120):
              self.details_label.insert(i, 0)
              self.details_label[i] = QLabel(" ")
              ProgressThreads.addWidget(self.details_label[i])
              ProgressThreads.addSpacing(6)
              self.details_label[i].setText(Tools.Trim.Short('Idle', 7))
              self.GU.insert(i, Cr())
              self.GU[i].start()
  
          self.connect(self.GU, QtCore.SIGNAL("host_UP"), self.UpdateHost)
  
  
      def UpdateHost(self, str1, pos1):
          self.details_label[pos1].setText(str1)
  
  
  class guiUpdate():
      def GUI_main(self):
          self.GUI = GUI
  
  
  
  if __name__ == "__main__": 
      app = QApplication(sys.argv)
      guiUpdate.GUI_main.GUI = Main_Window()
      sys.exit(app.exec_())
  </code></pre>
  
  <p>Thank you for the help :)</p>
  
  <p><strong>UPDATE</strong>
  The script below is a hopefully correct PyQt5 version of the script above. However the issue of crashing and 'not responding' message is still unresolved</p>
  
  <pre><code>from time import sleep
  import os
  from PyQt5 import QtCore, QtGui, uic
  from PyQt5.QtWidgets import *
  from PyQt5.QtCore import QObject, pyqtSignal
  import random
  import os
  import time
  import Tools
  import sys
  
  
  class Cr(QtCore.QThread):
      def __init__(self, sam):
          QtCore.QThread.__init__(self)
          self.sam = sam
  
      def run(self):
  
          while True:
              rndInt = random.randint(1, 100000)
              timesleep = random.random()
              time.sleep(timesleep)
              for i in range(5):
                  #time.sleep(1)
  
                  self.sam.connect_and_emit_trigger('foo' + str(rndInt), i)
                  #self.emit(QtCore.SIGNAL('host_UP'), 'foo' + str(rndInt), i)
                  #QtGui.QApplication.processEvents()
  
  
  class Main_Window(QWidget):
  
      def __init__(self, *args): 
          QWidget.__init__(self, *args)
          self.relativePath = os.path.dirname(sys.argv[0])
  
          self.Main_Window = uic.loadUi("Main_Window.ui", self)
          self.Main_Window.show()
          self.Main_Window.move(790, 300)
  
          sam = Foo()
  
  
          self.GU = []
          ProgressThreads = self.ProgressThreads
          self.details_label = []
          for i in range(5):
              self.details_label.insert(i, 0)
              self.details_label[i] = QLabel(" ")
              ProgressThreads.addWidget(self.details_label[i])
              ProgressThreads.addSpacing(6)
              self.details_label[i].setText(Tools.Trim.Short('Idle', 7))
              self.GU.insert(i, Cr(sam))
              self.GU[i].start()
  
  
  class Foo(QObject):
      # Define a new signal called 'trigger' that has no arguments.
      trigger = pyqtSignal()
      def connect_and_emit_trigger(self, str, i):
          self.str = str
          self.i = i
  
          self.trigger.connect(self.handle_trigger)
          self.trigger.emit()
  
      def handle_trigger(self):
          guiUpdate.GUI_main.GUI.details_label[self.i].setText(self.str)
  
  
  
  
  class guiUpdate():
      def GUI_main(self):
          self.GUI = GUI
  
  
  
  if __name__ == "__main__": 
      app = QApplication(sys.argv)
      guiUpdate.GUI_main.GUI = Main_Window()
      sys.exit(app.exec_())
  </code></pre>