我已经重新实现了 QSqlTableModel.select() 以在视图中显示模型返回的所有结果:
def select(self):
self.setTable("videos")
results = QtSql.QSqlTableModel.select(self)
self.setHeaderData(5, QtCore.Qt.Horizontal, "", QtCore.Qt.DisplayRole)
self.setHeaderData(6, QtCore.Qt.Horizontal, "Modification")
self.setHeaderData(9, QtCore.Qt.Horizontal, "Ajout")
while self.canFetchMore():
self.fetchMore()
return results
我想对函数 setQuey 做同样的事情,所以我尝试了类似的方法:
def setQuery(self, query):
results = QtSql.QSqlTableModel.setQuery(query)
self.select(results)
while self.canFetchMore():
self.fetchMore()
return results
但我得到了这个例外:
File "/home/djipey/informatique/python/bibli/model.py", line 23, in setQuery
results = QtSql.QSqlTableModel.setQuery(query)
TypeError: QSqlTableModel.setQuery(QSqlQuery): first argument of unbound method must have type 'QSqlTableModel'
你能解释一下为什么我有一个 typeError 吗?我真的不明白。