Answer the question
In order to leave comments, you need to log in
How to override the data method of QSqlQueryModel and get the cell value in it?
Can you please tell me how to display the value of the cell in the overridden data method?
QVariant PlayerModel::data(const QModelIndex &index, int role) const
{
QVariant value = index.data(); // тут моя програмка крашится.
switch (role){
case Qt::DisplayRole:
return value;
default:
return QVariant::Invalid;
}
}
int column = index.column();
if(column==2) int val = index.data().toInt();
Answer the question
In order to leave comments, you need to log in
QModelIndex::data() is implemented to return QAbstractItemModel::data(). You override QAbstractItemModel::data() and call QModelIndex::data() on it to get the value. There is an endless mutual call of functions and the program crashes. In general, to get the current value in QAbstractItemModel::data(), you must use the parent class method:
QVariant value = QSqlQueryModel::data(index, role);
To modify values in data, you need to implement your own filter based on QAbstractProxyModel
Yes, I'm not that to modify. I need to change the cell background depending on the value.
Can this be done without a delegate and its own filter?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question