使用 PyQt4 4.8.6 下面的代码会产生错误
QObject::startTimer:QTimer 只能用于以 QThread 启动的线程
当 a 用作 QApplication 的变量时,但如果 cpp(或大多数其他任何东西)用于该变量,则不会产生错误。这是 PyQt4 中的错误还是我遗漏了什么?
#! /usr/bin/env python
# This is only needed for Python v2 but is harmless for Python v3.
import sip
sip.setapi('QVariant', 2)
from PyQt4 import QtGui
#def main():
if __name__ == '__main__':
import sys
if len(sys.argv) > 1:
use_a = False
print "Don't use a"
else:
use_a = True
print "Use a"
if use_a:
a = QtGui.QApplication(sys.argv)
else:
cpp = QtGui.QApplication(sys.argv)
model = QtGui.QStandardItemModel(4,2)
tableView = QtGui.QTableView()
tableView.setModel(model)
tableView.show()
if use_a:
sys.exit(a.exec_())
else:
sys.exit(cpp.exec_())
#if __name__ == '__main__':
# main()
最佳答案
这可能不是错误。
当 Python 开始关闭时,对象被垃圾回收的顺序可能无法预测。您看到的错误消息很可能是它的副作用。
这会导致您的应用程序出现真正的问题吗?
如果不是,就适当重命名,忘掉它吧...
关于python - PyQt4 导致 QThread 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8995367/