Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This is an example of how to properly do multi-threading in PyQt 4.
- # This is a stripped down version of the code, in order to emphasize
- # the multi-threading proccess. To view the full code, go to
- # www.github.com/mathomastech/HBS_Communicator
- # The files of interest in handler.py and worker.py
- #worker.py
- from PyQt4 import QtCore
- from communicator import Communicator
- class Worker(QtCore.QThread):
- update_online_list = QtCore.pyqtSignal()
- def __init__(self, parent=None):
- QtCore.QThread.__init__(self)
- def run (self):
- # Do a bunch of long running logic here
- # Emit signal to main thread
- self.update_online_list.emit()
- return
- # handler.py
- from PyQt4 import QtGui, QtCore
- from communicator import Communicator
- from worker import Worker
- class Handler(QtGui.QMainWindow):
- def __init__(self):
- super(Handler,self).__init__()
- # Threading
- QtCore.QThread.currentThread().setObjectName("MAIN")
- self.thread = QtCore.QThread()
- self.thread.name = "auto_refresh"
- self.worker = Worker()
- self.worker.moveToThread(self.thread)
- self.worker.start()
- self.worker.update_online_list.connect(self.online_list)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement