Python QThread 变量未发送

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

我正在使用 qtread 的胎面。 在胎面内部,我计算了向主发出的角度,以便更新 GUI。 但我在旋转图像中得到的值很奇怪。例如,胎面中计算的角度是 45.66619997018314,但我在函数中得到的是 -433762864。

我了解 python 的基础知识,我正在学习 QT,所以请耐心等待:)

提前致谢

我正在使用这个线程:

import settings
import util

from PyQt5.QtCore import QThread, pyqtSignal
import time
import screenrec
import cv2
from PyQt5 import QtGui

class CompassThread(QThread):
    rotateImage = pyqtSignal(int)
    updateVariables = pyqtSignal(int)

    def __init__(self, parent=None):
        QThread.__init__(self, parent=parent)
        self._isRunning = True

    def run(self):
        while self._isRunning == True:
            settings.currentAngle = screenrec.getCurrentAngleCV()
            print("set", settings.currentAngle)
            self.rotateImage.emit(settings.currentAngle)
            time.sleep(2)

    def stop(self):
        self._isRunning = False
        self.terminate()

我调用的函数是这个:

def rotate_image(self, angle):
    print("angle", angle)
    self.image = settings.compass_image
    self.image = util.rotateImage(self.image, settings.compassPreviousAngle)
    self.image = QtGui.QImage(self.image.data, self.image.shape[1], self.image.shape[0],
                              QtGui.QImage.Format_RGB888).rgbSwapped()
    self.image_frame.setPixmap(QtGui.QPixmap.fromImage(self.image))
    self.show()

我主要是这样表述的:

        self.compassThread = compassthread.CompassThread(self)
        self.compassThread.rotateImage.connect(lambda angle: compassthread.rotate_image(self, angle))
        self.compassThread.updateVariables.connect(lambda angle: updateVariables(angle))
        self.compassThread.start()
python signals qthread
1个回答
0
投票

45.666199970183141
不是
int

我会避免在信号中发送任何对象,而只是将结果放入queue中,这样QT只处理“信号”,而python处理python对象。

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