QThread.isFinished returns False in slot connected to finished() signal

最后都变了- 提交于 2019-12-12 16:21:11

问题


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:

isFinished: False

answer in another SO question(QThread emits finished() signal but isRunning() returns true and isFinished() returns false) suggests that it should be like this:

  1. At this point, isFinished() should start returning true and isRunning() false.
  2. The internals emit the finished() signal.
  • py 2.7.4
  • PySide 1.1.2
  • Qt 4.8.2

also tested with PyQt4


回答1:


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.



来源:https://stackoverflow.com/questions/20724148/qthread-isfinished-returns-false-in-slot-connected-to-finished-signal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!