sending data to a different thread
-
Hi all,
I am at the beginning of my learning curve, and trying to understand how to solve a problem i have.
I'm having a main class. in this main class I have a instance of another class that runs on a different QThread.
This code emits a signal that I can access from my main class (above) like this:def getImage(self): self.thread = QThread() self.worker = Worker() self.worker.imagesignal.connect(self.setImage) def setImage(self, img, imgOriginal, classname = str, score = float): ... some more code here... class Worker(QObject): finished = pyqtSignal() imagesignal = pyqtSignal(numpy.ndarray, numpy.ndarray, str, float) def run(self): h = Harvester() ia = yoloRun.open_stream(h) model = yoloRun.loadNetwork() while 1: im0, imgOr, classname, score = yoloRun.run(imageAcq=ia, model=model) self.imagesignal.emit(im0, imgOr, classname, score) self.finished.emit()
now, what I would need to do, is to send a trigger back (simple bool variable) to the worker thread. (i want to add after the while1: an event.
I tried to declare the signal in my main class like this:
startCameraSignal = pyqtSignal(bool) self.startCameraSignal.emit(True)
but I don't know how to detect the signal from the instance of worker...
Is this even the correct way of doing it?
Thank you
Best regards
Igor
-
Hi,
It's usually done through a slot.
One note: do not use while 1. Doing so you do not have any clean way to stop your loop.