refactor: initialize QTimer with parent and ensure proper thread cleanup on stop
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user