QSqlQueryModel headerData Qt::Vertical Display keep increasing the row numbers
-
i SubClassed the QSqlQueryModel and i try to calculate the Vertical header display based on select query . the wierd thing here is that the headerData method keep calling itself and the number ofcource keep increasing . why ? isn't it called as many times as the rows displayed? this is my function
@QVariant ListSqlModel::headerData(int section, Qt::Orientation orientation, int role) const
{if(orientation == Qt::Vertical && role == Qt::DisplayRole) { int returnHeaderCount = iHeaderCount; QString h = QString::number(returnHeaderCount); LOG_MSG("RowCount:"+h.toStdString()); iHeaderCount++; return returnHeaderCount; }
}
@ -
You cannot rely on the fact that headerData is only called once.
If you have pagination, I would add an attribute to the model, holding the current start index (= offset from the start) of the result set (as passed to limit/offset in the query) and in headerData just add that offset to the section number. This way your return value is always the same.