伪代码
from PyQt5.QtCore import pyqtSignal, QObject
class TestManager(QObject):
sendmsg = pyqtSignal(str)
def __init__(self):
super(TestManager, self).__init__()
self.bstart = True
self.image = None
self.event = threading.Event()
threading.Thread(target=self.__read_image).start()
def __read_image(self):
while self.bstart:
self.event.wait()
self.sendmsg.emit("加载图像中...")
#这里做耗时操作...
self.sendmsg.emit("图像加载完毕")
self.event.clear()
def set_image(self, opencv_img):
self.image = opencv_img
self.event.set()
def __del__(self):
self.bstart = False