From 2c1233f3043d1bc560ce4f88c99adbd47a9ebf66 Mon Sep 17 00:00:00 2001 From: bartool Date: Mon, 13 Oct 2025 19:36:09 +0200 Subject: [PATCH] refactor: initialize QTimer with parent and ensure proper thread cleanup on stop --- core/camera/camera_controller.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/camera/camera_controller.py b/core/camera/camera_controller.py index fd39c8b..f6530e9 100644 --- a/core/camera/camera_controller.py +++ b/core/camera/camera_controller.py @@ -23,7 +23,7 @@ class CameraWorker(QObject): @Slot() def initialize_worker(self): """Initializes the timer in the worker's thread.""" - self.timer = QTimer() + self.timer = QTimer(self) self.timer.timeout.connect(self._update_frame) @Slot(BaseCamera, int) @@ -138,12 +138,15 @@ class CameraController(QObject): # Initialize worker when thread starts self._thread.started.connect(self._worker.initialize_worker) + self._thread.finished.connect(self._worker.stop_camera) self._thread.start() def stop(self): - self._thread.quit() - self._thread.wait() + if self._thread.isRunning(): + self._thread.quit() + self._thread.wait() + self._thread.deleteLater() def set_camera(self, camera: BaseCamera, fps: int = 15) -> None: self._set_camera_requested.emit(camera, fps)