forked from Answeror/lit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdothread.py
42 lines (33 loc) · 818 Bytes
/
dothread.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from qt.QtCore import (
QThread,
QObject,
QCoreApplication,
QMetaObject,
Qt,
Slot,
Signal,
QRunnable,
QThreadPool
)
class Job(QObject):
finished = Signal()
@Slot()
def run(self):
print("job thread: %d" % QThread.currentThreadId())
self.finished.emit()
def finished():
print("post thread: %d" % QThread.currentThreadId())
if __name__ == '__main__':
import sys
app = QCoreApplication(sys.argv)
print("main thread: %d" % QThread.currentThreadId())
thread = QThread()
thread.start()
job = Job()
job.finished.connect(finished, Qt.QueuedConnection)
job.moveToThread(thread)
QMetaObject.invokeMethod(job, 'run', Qt.QueuedConnection)
app.exec_()
thead.wait()