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. QStandardItemModel::setItemData() removes data from roles where it shouldn't

QStandardItemModel::setItemData() removes data from roles where it shouldn't

Scheduled Pinned Locked Moved General and Desktop
qstandarditemqstandarditemmo
3 Posts 2 Posters 2.6k Views
  • 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.
  • sahadumS Offline
    sahadumS Offline
    sahadum
    wrote on last edited by
    #1

    Hi,

    I use a QStandardItemModel with a QTreeView. The QStandardItem's inside the model have some userdefined roles (Qt::UserRole + ...). I use

    QStandardItemModel::setItemData(const QModelIndex & index, const QMap<int, QVariant> & roles)
    

    to set multiple roles at the same time. The documentation of this function explains that roles not mentioned in the QMap of roles will NOT be modified. But after a call to setItemData() i lost the data of other roles.

    Test: read data from a user role before and after a call to setItemData()
    My code :

    // ... do stuff then...
    QMap<int, QVariant> mapRoles;
    mapRoles.insert( Qt::DisplayRole, strValue );
    mapRoles.insert( DATA_MODEL_ROLE_ITEM_DATA, varValue );
    
    // DEBUG
    // get data from user role "item_format"
    auto listFormat = iter->sibling( currentRow, DATA_MODEL_COLUMN_VALUE ).data( DATA_MODEL_ROLE_ITEM_FORMAT ).toList();
    
    QModelIndex idxItemValue = iter->sibling( currentRow, DATA_MODEL_COLUMN_VALUE );
    // set data of roles to item
    m_dataStoreModel->setItemData( idxItemValue, mapRoles );
    
    // DEBUG
    listFormat.clear();
    // get data from user role "item-format"
    listFormat = iter->sibling( currentRow, DATA_MODEL_COLUMN_VALUE ).data( DATA_MODEL_ROLE_ITEM_FORMAT ).toList();
    

    The result is that the first time I get the data from the user role to the 'listFormat' I can see the elements of the list. The second time I get an empty list.

    I looked at the implementation of QStandardItemPrivate::setItemData() (qstandarditemmodel.cpp) and there I can't see an append-like functionality.

    But maybe i missed something or doing something wrong? Or is there a bug in the setItemData() implementation?

    thx

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by sierdzio
      #2

      If what the function does differs from the documentation, then you have found a bug. Please report it on (including a minimal compilable example) Qt Jira. Additionally, if it used to work in previous versions of Qt, this is a regression and if marked as such it should get much more attention.

      (Z(:^

      1 Reply Last reply
      1
      • sahadumS Offline
        sahadumS Offline
        sahadum
        wrote on last edited by
        #3

        Hi,

        thx, I added a report to Qt Jira.

        QTBUG-45114

        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