天天看点

PYQT4 多线程框架

from PyQt4 import QtCore, QtGui
from frame import Ui_MainWindow
import sys

# 线程1的类
class thread1_class(QtCore.QObject):
    # 创建信号。。。
    signal_thread1_xxx = QtCore.pyqtSignal(str)
    def __init__(self, parent=None):
        super(self.__class__, self).__init__(parent)
        # todo 初始化线程。。。
    def fun1(self):
        # todo 实现功能。。。

# 线程2的类
class thread2_class(QtCore.QObject):
    # 创建信号。。。
    signal_thread2_xxx = QtCore.pyqtSignal(str)
    def __init__(self, parent=None):
        super(self.__class__, self).__init__(parent)
        # todo 初始化线程。。。
    def fun1(self):
        # todo 实现功能。。。

# UI线程
class surface(QtGui.QMainWindow):
    # 创建信号。。。
    signal_surface_xxx = QtCore.pyqtSignal(str,int)
    signal_surface_yyy = QtCore.pyqtSignal(str,int)
    def __init__(self):
        super(surface, self).__init__()
        # 类Ui_MainWindow 由QTdesigner生成的ui文件转化得到
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        
        # todo 初始化控件。。。
        # blabla。。。

        # 创建线程
        self.thread1= QtCore.QThread()
        self.thread1_entity = thread1_class()
        self.thread1_entity.moveToThread(self.thread1)
        # 连接信号到线程
        self.signal_surface_xxx.connect(self.thread1_entity.fun1)
        # 从线程连接信号
        self.thread1_entity.signal_thread1_xxx.connect(self.fun1)
    
    def fun1(self, param...):
        # todo 实现功能	。。。
	
def main():
	app = QtGui.QApplication(sys.argv)
	win = surface()
	win.show()
	sys.exit(app.exec_())

if __name__ == "__main__":
	main()
           

继续阅读