1、主要代碼邏輯python
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+ "\n" 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/83790074app