zoukankan      html  css  js  c++  java
  • pyqt5多线程-简单例子

    一、主要代码逻辑

    from PyQt5 import QtWidgets, QtCore
    from testqt.TEST_QT_FROM import Ui_Dialog
    import sys
    from PyQt5.QtCore import *
    import time
    
    
    # 继承QThread
    class Runthread(QtCore.QThread):
        # python3,pyqt5与之前的版本有些不一样
        #  通过类成员对象定义信号对象
        _signal = pyqtSignal(str)
    
        def __init__(self):
            super(Runthread, self).__init__()
    
        def __del__(self):
            self.wait()
    
        def run(self):
            print("run 666")
            self._signal.emit("run 666"); # 信号发送
    
    
    
    class TestQtFromC(QtWidgets.QWidget, Ui_Dialog):
        text =""
        def __init__(self):
            super(TestQtFromC, self).__init__()
            self.setupUi(self)
    
        #click
        def timer_click(self):
            self.thread = Runthread() # 创建线程
            self.thread._signal.connect(self.callbacklog) # 连接信号
            self.thread.start() # 开始线程
    
        # callback
        def callbacklog(self, msg):
            self.text =self.text+time.strftime("%Y-%m-%d %H:%M:%S ", time.localtime())+msg+ "
    "
            print(self.text)
            # 回调数据输出到文本框
            self.textEdit.setText(self.text);
    
    
    if __name__ == "__main__":
        app = QtWidgets.QApplication(sys.argv)
        mTestQtFromC = TestQtFromC()
        mTestQtFromC.show()
        sys.exit(app.exec_())
    

    转自:https://blog.csdn.net/iknownu/article/details/83790074

      

  • 相关阅读:
    Numpy 里线性代数函数
    lateral view 使用方法
    Numpy 基础函数
    Numpy 基础操作
    pandas 基础操作记录学习
    pandas向左移动非空单元格
    供应商自动记账
    SAP Smartforms 参数配置
    SAP FPM 相关包 APB_FPM_CORE
    SAP BPC 清除CUBE 中的数据
  • 原文地址:https://www.cnblogs.com/hester/p/11414547.html
Copyright © 2011-2022 走看看