使用 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()