问题描述
我有一个发出完成()信号的 QThread,但它的 isFinished() 返回 False.这是为什么?如何知道 isFinished 何时开始返回 True?
from __future__ import print_function从 PySide 导入 QtCore、QtGuiqapp = QtGui.QApplication([])worker_thread = QtCore.QThread()worker_thread.start()worker_thread.quit()定义鳍():print('isFinished:', worker_thread.isFinished())worker_thread.finished.connect(fin)QtCore.QTimer.singleShot(200, qapp.quit)qapp.exec_()
有时它返回真,但大多数时候它输出:
已完成:错误
在另一个 SO 问题中回答(QThread 发出 finished() 信号但 isRunning() 返回 true 并且 isFinished() 返回 false) 建议它应该是这样的:
- 此时,isFinished() 应该开始返回 true 和 isRunning() false.
- 内部发出完成的()信号.
- py 2.7.4
- PySide 1.1.2
- Qt 4.8.2
也用 PyQt4 测试
原来是 qt 中的一个错误 (https://bugreports.qt-project.org/browse/QTBUG-30251) 已在 Qt 4.8.5 中修复.PySide 1.2.1 附带 Qt4.8.5.
I have a QThread that emits finished() signal, but its isFinished() returns False.Why is that? How to know when isFinished will start to return True?
from __future__ import print_function
from PySide import QtCore, QtGui
qapp = QtGui.QApplication([])
worker_thread = QtCore.QThread()
worker_thread.start()
worker_thread.quit()
def fin():
print('isFinished:', worker_thread.isFinished())
worker_thread.finished.connect(fin)
QtCore.QTimer.singleShot(200, qapp.quit)
qapp.exec_()
sometimes it returns true, but most of the time it outputs:
answer in another SO question(QThread emits finished() signal but isRunning() returns true and isFinished() returns false) suggests that it should be like this:
- py 2.7.4
- PySide 1.1.2
- Qt 4.8.2
also tested with PyQt4
Turns out it was a bug in qt (https://bugreports.qt-project.org/browse/QTBUG-30251) which is fixed in Qt 4.8.5.PySide 1.2.1 comes with Qt4.8.5.
这篇关于QThread.isFinished 在连接到 finished() 信号的插槽中返回 False的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!