class EventHookThread(QThread):
setHwndSignal = Signal(int)
def __init__(self):
super().__init__()
self.setHwndSignal.connect(self.set_hwnd)
self.moveToThread(self)
def run(self):
threading.current_thread().name = f"EventHookThread {threading.currentThread().native_id}"
logger.warning(f"run thread: {threading.currentThread().native_id} {threading.current_thread().name}")
self.exec()
@Slot(int)
def set_hwnd(self, hwnd):
logger.warning(f"set_hwnd: {threading.currentThread().native_id} {threading.current_thread().name}")
logger.warning(f"set_hwnd {hwnd}")
if hwnd is None:
return
방법1. event_hook_thread.setHwndSignal.emit(hwnd)
방법2. QMetaObject.invokeMethod(event_hook_thread, "set_hwnd", Qt.QueuedConnection, Q_ARG(int, hwnd))
Q_ARG(int, hwnd) => 이 코드가 중요