Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. can't read data from stored data with Qt::UserRole and custom QStandardItemModel()
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mete
    wrote on last edited by mete
    #1

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

    VRoninV 1 Reply Last reply
    0
    • M mete

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

      VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      @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())

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      M 1 Reply Last reply
      2
      • VRoninV VRonin

        @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())

        M Offline
        M Offline
        mete
        wrote on last edited by
        #3

        @VRonin thank you very much

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved