使用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 …Run Code Online (Sandbox Code Playgroud)