Solved PyQt- losing worker object after QThread has started
-
Hi All
I have a QThread that I run a QObject worker on. I connect to it like this;
def startWorker(self): updateworker = Worker() updateworker.moveToThread(self.thread) updateworker.sendQImages.connect(self.receiveQImages) self.sendImagesToWorker.connect(updateworker.processImages) self.deleteWorkerObject.connect(updateworker.deleteWorker) self.thread.start()
I can't seem to communicate with it, at all, once its been started. I have a logger in the worker, which writes to the log on init, but thereafter is silent. Anyone know what could be wrong? I'm checking that the QThread is running before calling signal to communicate with it, and the thread is running.
-
Blocking the event loop?
-
I've got Py_BEGIN_ALLOW_THREADS within the function that I'm calling, in the worker. But the function isnt actually being called because the logger is supposed to write to the log before that line. How do I know if the QThread is blocking the event loop?
-
@robbiecooper said in PyQt- losing worker object after QThread has started:
How do I know if the QThread is blocking the event loop?
It's you who may be blocking it, not the QThread class. If you have a long-running loop (like
while (true)
or equivalent, sorry I don't know Python) then you will never return control to the thread's event loop and you won't be able to get any slots that are invoked through signals from other threads. -
Ok thanks I'll check. Don't think so but its worth a punt!
-
It may be worth having a look here as well:
https://forum.qt.io/topic/81501/another-beginner-design-question -
@robbiecooper said in PyQt- losing worker object after QThread has started:
updateworker
this updateworker variable is a local variable and is destroyed when startWorker finishes.
-
@jsulm said in PyQt- losing worker object after QThread has started:
this updateworker variable is a local variable and is destroyed when startWorker finishes.
Ah, I though it was something like a heap allocation, well that's what I get for not keeping my hole shut. :)
-
@jsulm Ah yes- makes total sense! Thanks very much!