refactor: initialize QTimer with parent and ensure proper thread cleanup on stop

This commit is contained in:
2025-10-13 19:36:09 +02:00
parent feebc5153a
commit 2c1233f304

View File

@@ -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):
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)