K
K
Konstantin2015-03-24 17:21:52
Qt
Konstantin, 2015-03-24 17:21:52

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;
    }
}

even if I know the data type of the cell, I can't get the value either - it crashes:
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

3 answer(s)
P
Pavel, 2015-03-27
@happy_yar

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);

A
Armenian Radio, 2015-03-24
@gbg

To modify values ​​in data, you need to implement your own filter based on QAbstractProxyModel

K
Konstantin, 2015-03-24
@happy_yar

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 question

Ask a Question

731 491 924 answers to any question