Solved signal emit, but the slot function is not called.
-
signal emit, but the slot function is not called.
Please tell me why.import sys from PySide6.QtCore import ( QThread, QObject, Signal, Slot, Qt, ) from PySide6.QtWidgets import QApplication from loguru import logger class Model(QObject): signalCommand = Signal(bool) @property def command(self) -> bool: return self._command @command.setter def command(self, value: bool) -> None: self._command = value self.signalCommand.emit(value) logger.info(f'model set {value}') def __init__(self): super().__init__() self._command = False class ControlThread(QThread): @property def isRunning(self) -> bool: return self.__threadRunning @isRunning.setter def isRunning(self, value: bool) -> None: self.__threadRunning = value def __init__(self, model: Model): super().__init__() self.isRunning = True self.__model = model def __del__(self): self.stop() def run(self) -> None: if not self.isRunning: self.isRunning = True while self.isRunning: self.msleep(1000) if self.__model.command: self.__model.command = False else: self.__model.command = True def stop(self) -> None: self.isRunning = False class Control(QObject): def __init__(self, model: Model): super().__init__() self.__model = model self.controlThread = ControlThread(self.__model) self.controlThread.start() def __del__(self): self.__stopThread() def __stopThread(self) -> None: self.controlThread.stop() self.controlThread.quit() self.controlThread.wait() class View(QObject): def __init__(self, model: Model, control: Control): super().__init__() self._model = model self._control = control self._model.signalCommand.connect(self.__command) @Slot(bool) def __command(self, value: bool): logger.info(f'__command {value}') class App(QApplication): def __init__(self, sys_argv): super(App, self).__init__(sys_argv) model_ = Model() control_ = Control(model_) view_ = View(model_, control_) if __name__ == '__main__': app = App(sys.argv) sys.exit(app.exec())
-
@kwon4308 said in signal emit, but the slot function is not called.:
model_ = Model() control_ = Control(model_) view_ = View(model_, control_)
How does anything work given that these are all local variables?
-
@JonB Wow, how did I not see that? Thank you so much. You're the best.
-