我正在尝试向线程发送带有两个参数的信号,但没有传输数据

问题描述 投票:0回答:1

我需要将内容更新的字符串发送到我的线程,这会将其发送到 pico w。 在附加的代码片段中,我可以将参数发送到主窗口中的套接字。但是当向线程发送相同的信号时我收到错误, Worker.commData() 缺少 2 个必需的位置参数:“mes”和“f”。

尝试了几天后,我还没有找到吸力。有人可以帮忙吗?

#! /usr/bin/python3

from PyQt5 import QtWidgets, QtCore
import sys

# create serial read worker

class Worker(QtCore.QObject):

    @QtCore.pyqtSlot()
    def __init__(self):
        super(Worker, self).__init__()
        self.working = True

    def work(self):
        if self.working == True:
       # create test increment timer object
            timerT = QtCore.QTimer(self)
            timerT.timeout.connect(self.comms)
            timerT.start(500) 

    @QtCore.pyqtSlot()
    def commData(self, mes, f):
        print(mes)
        print(f)

    def comms(self):
        pass

# Main Window

class MainWindow(QtWidgets.QMainWindow):
    sendReady = QtCore.pyqtSignal(str, bool)

工人开始

    def workStart(self):
        self.worker = Worker()self.worker.moveToThread(self.thread)
        self.thread.started.connect(self.worker.work)
        self.sendReady.connect(self.printOut)           # connection ok
        self.sendReady.connect(self.worker.commData)    # connection NO DATA
        self.thread.start() 

# Start Window 

    def __init__(self):
        super().__init__()
        self.setWindowTitle('Auto Watering System')       
        self.setMinimumWidth(300)
        self.setMinimumHeight(300)
        self.workStart()
        print("start")
        mes = "99999"
        f = True
        self.sendReady.emit(mes, f)  # connect to pico server

    def printOut(self,mes, f):
        print(mes)
        print(f)
  

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    window = MainWindow()
    window.show()
    app.exec_()

1 将连接线移至传出处。 2 尝试仅使用 i 参数。

multithreading signals pyqt6
1个回答
0
投票

self.thread = QThread()
不见了

© www.soinside.com 2019 - 2024. All rights reserved.