| 18 | |
| 19 | |
| 20 | class ThreadQt(QThread): |
| 21 | |
| 22 | def __init__(self, textBrowser, *args, **kwargs): |
| 23 | super(ThreadQt, self).__init__(*args, **kwargs) |
| 24 | self._textBrowser = textBrowser |
| 25 | |
| 26 | def stop(self): |
| 27 | self.requestInterruption() |
| 28 | |
| 29 | def run(self): |
| 30 | while not self.isInterruptionRequested(): |
| 31 | text = datetime.now().strftime('%Y-%m-%d %H:%M:%S') |
| 32 | # 通过`invokeMethod`直接调用对应的槽函数 |
| 33 | # 1. 获取函数`isReadOnly1`返回值, self.parent() 是Window窗口对象 |
| 34 | # NOTE:注意这里获取返回值要用 `Qt.DirectConnection` 方式 |
| 35 | retValue = QMetaObject.invokeMethod(self.parent(), 'isReadOnly1', |
| 36 | Qt.DirectConnection, |
| 37 | Q_RETURN_ARG(bool)) |
| 38 | # 2. 通过`invokeMethod`队列调用对应控件槽函数`append` |
| 39 | argValue = Q_ARG(str, text + ' readOnly: ' + str(retValue)) |
| 40 | QMetaObject.invokeMethod(self._textBrowser, 'append', |
| 41 | Qt.QueuedConnection, argValue) |
| 42 | self.sleep(1) |
| 43 | |
| 44 | |
| 45 | class ThreadPy(Thread): |