can't read data from stored data with Qt::UserRole and custom QStandardItemModel()



  • Hi all,
    I build QTableview and QStandardItemModel as model. When i store data with
    QStandardItem ....itm->setData(qw,Qt::UserRole); and after i can reach the data with index....data(Qt::UserRole).toInt(); successfully.
    But when i customize QStandardItemModel and reuse "data(const QModelIndex &index, int role) const" i can't reach indexed data. What value should i return in function or what am i missing?

    I tried as below list code but failed.

    data(const QModelIndex &index, int role) const
    ..
    if (role == Qt::UserRole)
    {
    return QVariant(index.data(Qt::UserRole).toInt())
    }
    or
    if (role == Qt::UserRole)
    {
    return QVariant();
    }



  • @mete said in can't read data from stored data with Qt::UserRole and custom QStandardItemModel():

    return QVariant(index.data(Qt::UserRole).toInt())

    will just call an infinite recursion and converting a variant to an int and back to a variant has no practical application I can see but anyway...
    return QVariant(QStandardItemModel::data(index,Qt::UserRole).toInt())



  • @VRonin thank you very much


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.