0

I have already reimplemented QSqlTableModel.select() to display all the results returned by the model in the view:

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

I would like to do the same thing with the function setQuey, so I tried something like that:

def setQuery(self, query):


    results = QtSql.QSqlTableModel.setQuery(query)
    self.select(results)

    while self.canFetchMore():
        self.fetchMore()
    return results

But I got this exception:

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'

Could you explain to me why I have a typeError ? I don't really understand.

1 Answer 1

1

Just as your override takes two parameters,

def setQuery(self, query):

the call to QtSql.QSqlTableModel.setQuery requires two parameters:

results = QtSql.QSqlTableModel.setQuery(self, query)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.