标签: qrunnable

完成后将 QRunnable 连接到函数/方法

QThread 有一个完成的信号,当线程完成时我可以做一些事情(连接到一个方法/函数),但是我也想用 QRunnable 来做这件事。有没有办法在完成后将 QRunnable 线程连接到方法/函数?

Q线程:

class HelloWorldTask(QThread):
    def __init__(self):
        QThread.__init__(self)
    def run(self):
        import time
        time.sleep(3)
        print ("Running thread \n")
        time.sleep(3)

hello.finished.connect(check)

def check():
    print('Thread Done')
Run Code Online (Sandbox Code Playgroud)

输出:

运行线程

完成的

QRunnable:

instance = QThreadPool.globalInstance()


class HelloWorldTask(QRunnable):
    def __init__(self):
        super().__init__(self)
    def run(self):
        import time
        time.sleep(3)
        print ("Running thread \n")
        time.sleep(3)

hello = HelloWorldTask()
#hello.finished.connect(check) <-- how to connect to a method/function when finished.
instance.start(hello)
print(instance.waitForDone())

def check():
    print('Thread Done')

Run Code Online (Sandbox Code Playgroud)

所需的输出:

运行线程

线程完成

python pyqt python-3.x pyqt5 qrunnable

3
推荐指数
1
解决办法
1255
查看次数

标签 统计

pyqt ×1

pyqt5 ×1

python ×1

python-3.x ×1

qrunnable ×1