MCPcopy Index your code
hub / github.com/PyQt5/PyQt / __init__

Method __init__

QThread/moveToThread.py:36–53  ·  view source on GitHub ↗
(self, *args, **kwargs)

Source from the content-addressed store, hash-verified

34class Window(QWidget):
35
36 def __init__(self, *args, **kwargs):
37 super(Window, self).__init__(*args, **kwargs)
38 layout = QVBoxLayout(self)
39 self.progressBar = QProgressBar(self)
40 self.progressBar.setRange(0, 100)
41 layout.addWidget(self.progressBar)
42 layout.addWidget(QPushButton('开启线程', self, clicked=self.onStart))
43
44 # 当前线程id
45 print('main id', QThread.currentThread())
46
47 # 启动线程更新进度条值
48 self._thread = QThread(self)
49 self._worker = Worker()
50 self._worker.moveToThread(self._thread) # 移动到线程中执行
51 self._thread.finished.connect(self._worker.deleteLater)
52 self._thread.started.connect(self._worker.run)
53 self._worker.valueChanged.connect(self.progressBar.setValue)
54
55 def onStart(self):
56 if not self._thread.isRunning():

Callers

nothing calls this directly

Calls 3

addWidgetMethod · 0.80
WorkerClass · 0.70
setRangeMethod · 0.45

Tested by

no test coverage detected