Issue PyQt5 QRunnable Signals
-
For some reason the signals I emit from my QRunnable are not triggered in the parent class. I am not able to figure out what the problem is.
The code reaches the "emitted" print statement in the qrunnable, but the pyqtslot is never been triggered.
class ImageConc(qtc.QObject) def __init__(self): super().__init__() self.pool = qtc.QThreadPool.globalInstance() def run_thread(self, images: list): # some stuff happening runner = RunnerConcatenate(images, location, class_name) runner.signals.finished.connect(self.__on_job_done) self.pool.start(runner) @qtc.pyqtSlot() def __on_job_done(self): print("Done")
class RunnerConcatenate(qtc.QRunnable): def __init__(self, sources: list, location: str, class_name: str): super().__init__() self.sources = sources self.location = location self.class_name = class_name self.signals = ConcatSignal() @qtc.pyqtSlot() def run(self): # Some stuff happening self.signals.finished.emit() self.signals.errors.emit(error) print("emitted") class ConcatSignal(qtc.QObject): finished = qtc.pyqtSignal() errors = qtc.pyqtSignal(list)
-
Hi,
You design is overly complicated and wrong. Signals should be triggered from within the class that declares them. Why do you have a separate class containing only these two signals ?
-
@lvlanson said in Issue PyQt5 QRunnable Signals:
Because I need to trigger the signal from an Object which is a QRunnable. From what I have read, QRunnable cannot have a signal object, since its not deriving from QObject.
It does not mean you cannot derive from both QObject and QRunnable. You just have to respect the order, first QObject then QRunnable.
-
Multiple inheritance not possible in Python ?
-
@SGaist
https://www.riverbankcomputing.com/static/Docs/PyQt5/gotchas.html#multiple-inheritanceMultiple Inheritance¶
It is not possible to define a new Python class that sub-classes from more than one Qt class. The exception is classes specifically intended to act as mixin classes such as those (like QQmlParserStatus) that implement Qt interfaces.
Dunno whether this affects/precludes the situation here, but it sounds like it does....