MCPcopy Create free account
hub / github.com/PyQt5/PyQt / ThreadQt

Class ThreadQt

QMetaObject/CallInThread.py:20–42  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18
19
20class 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
45class ThreadPy(Thread):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected