有人会解释我做错了什么吗?我在Win8上使用PyQt4。 以下是我的主要代码:
con = sqlite3.connect('storage.db')
with con:
cur = con.cursor()
cur.execute(script)
rows = cur.fetchall()
self.treeWidget.clear()
for row in rows:
self.treeWidget.addTopLevelItem(QTreeWidgetItem(row))
当我执行脚本时,
script = "SELECT number,name FROM CB WHERE day > {0} AND day < {1} GROUP BY number LIMIT {2} ;".format(self.start_day, self.final_day,self.spinBox.value())
工作正常。
但是当我执行
时script = "SELECT number,name,SUM(access)/1000000.0 FROM CB WHERE day > {0} AND day < {1} GROUP BY number ,name LIMIT {2} ;".format(self.start_day, self.final_day, self.spinBox.value())
显示错误:
Traceback (most recent call last):
File "G:/CBAnalysis/CB_analysis.py", line 155, in quickaccess
self.treeWidget.addTopLevelItem(QTreeWidgetItem(row))
TypeError: arguments did not match any overloaded call:
QTreeWidgetItem(int type=QTreeWidgetItem.Type): argument 1 has unexpected type 'tuple'
QTreeWidgetItem(QStringList, int type=QTreeWidgetItem.Type): argument 1 has unexpected type 'tuple'
QTreeWidgetItem(QTreeWidget, int type=QTreeWidgetItem.Type): argument 1 has unexpected type 'tuple'
QTreeWidgetItem(QTreeWidget, QStringList, int type=QTreeWidgetItem.Type): argument 1 has unexpected type 'tuple'
QTreeWidgetItem(QTreeWidget, QTreeWidgetItem, int type=QTreeWidgetItem.Type): argument 1 has unexpected type 'tuple'
QTreeWidgetItem(QTreeWidgetItem, int type=QTreeWidgetItem.Type): argument 1 has unexpected type 'tuple'
QTreeWidgetItem(QTreeWidgetItem, QStringList, int type=QTreeWidgetItem.Type): argument 1 has unexpected type 'tuple'
QTreeWidgetItem(QTreeWidgetItem, QTreeWidgetItem, int type=QTreeWidgetItem.Type): argument 1 has unexpected type 'tuple'
QTreeWidgetItem(QTreeWidgetItem): argument 1 has unexpected type 'tuple'
我确信这两个查询都是正确的,因为我在iPython中测试了它们。 但为什么我不能在PyQT4中执行第二个查询?
更新:将最后一行更改为
self.treeWidget.addTopLevelItem(QTreeWidgetItem(map(unicode,row)))
解决那个问题!感谢Gary Lee。