0

我已经重新实现了 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 吗?我真的不明白。

4

1 回答 1

1

就像您的覆盖需要两个参数一样,

def setQuery(self, query):

调用QtSql.QSqlTableModel.setQuery需要两个参数:

results = QtSql.QSqlTableModel.setQuery(self, query)
于 2013-07-26T16:19:55.767 回答