QObject::killTimer: Timers cannot be stopped from another thread QObject::~QObject: Timers cannot be stopped from another thread

Code Genie·2024년 11월 10일

서브스레드에서 생성한 QTimer를 안전하게 종료하기

메인스레드에서 프로세스 종료 이벤트 발생시

서브스레드 종료 메서드를 호출하도록 했는데

서브스레드에서 생성한 Qtimer 객체가 종료 되지 않아 문제 발생.

이전 코드

def stop(self):
    QMetaObject.invokeMethod(self.timer, "stop", Qt.QueuedConnection)
    self.quit()
    self.wait()

수정된 코드

def stop(self):
    QMetaObject.invokeMethod(self.timer, "stop", Qt.QueuedConnection)
    self.timer.deleteLater()
    self.quit()
    self.wait()

self.timer.deleteLater() 코드 추가 후 에러 없음

profile
1인 개발

0개의 댓글