Am subclassing QSqlRelationalTableModel.
class Titles(QSqlRelationalTableModel):
def __init__(self):
QSqlRelationalTableModel.__init__(self)
self.setTable("titles")
self.setRelation(self.fieldIndex("type"), QSqlRelation("title_type", "id", "type"))
self.select()
print self.record(0).value("title").toString() # 1
def data(self, i, role):
if role == Qt.DisplayRole:
print self.record(0).value("title").toString() # 2
return self.record(0).value("title").toString() # 3
titles = Titles()
print iswcTitlesModel.record(0).value("title").toString() # 4
All the above prints space (it returns the correct amount of rows, but only as blank space). If the data function is removed, #1 & #4 print. If doing return "string", all items are populated. The model is instantiated, and the intended return code works outside the model's definition. Tried multiple other SQL tables, all with a Relation, but even without a relation it doesn't work. Can anyone see what's going wrong?