我已经重新实现了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吗?我真的不明白。
答案 0 :(得分:1)
正如您的覆盖需要两个参数一样,
def setQuery(self, query):
对QtSql.QSqlTableModel.setQuery
的调用需要两个参数:
results = QtSql.QSqlTableModel.setQuery(self, query)