I have a PyQt GUI application with a main window and several workers of different types. I want to display notifications from the workers in the main window, something like:
class MainWindow(QMainWindow):
messageToDisplaySignal = pyqtSignal(str)
...
def displayStatus(self, s):
self.infoLabel.setText(s)
class Worker1(QThread):
...
def run(self):
self.parent.messageToDisplaySignal.emit('Worker1 started')
...
I saw recommendations to send only signals created by the object itself, but this is violated here. If I create messageToDisplaySignal in Worker1, I will also need to implement similar signals in all worker classes and to subscribe to them all in MainWindow. Is there a more proper way to go?
What is the exact reason of these recommendations (to send only signals created by the object itself) is another interesting question. What exactly will be bad otherwise?