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. QAbstractTableModel DisplayRole stop working
Forum Updated to NodeBB v4.3 + New Features

QAbstractTableModel DisplayRole stop working

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 397 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.
  • L Offline
    L Offline
    Lior
    wrote on last edited by
    #1

    hi,

    I implemented a simple QAbstractTableModel with my own roles.
    when I started implementing the view I tried to use the display role and it didn't work.

    i override the function

    QHash<int, QByteArray> CRowModel::roleNames() const
    

    when I disabled the function the display is working.

    1. if I override this function I can't use all the other roles that came with the QAbstractTableModel?
    2. can I explicitly add them to my hash table?
    JonBJ 1 Reply Last reply
    0
    • L Lior

      hi,

      I implemented a simple QAbstractTableModel with my own roles.
      when I started implementing the view I tried to use the display role and it didn't work.

      i override the function

      QHash<int, QByteArray> CRowModel::roleNames() const
      

      when I disabled the function the display is working.

      1. if I override this function I can't use all the other roles that came with the QAbstractTableModel?
      2. can I explicitly add them to my hash table?
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Lior
      I would guess that you need to add your extra names to the existing, default ones, not just replace them? Maybe your override needs something like:

      QHash<int, QByteArray> myRoleNames(QAbstractItemModel::roleNames());  // however you add all base role names
      myRoleNames[Qt::UserRole + 1] = "MyRole1";
      return myRoleNames;
      

      ?

      BTW, although I have never used QML, I don't think you have to bother to expand a model's rolenames with this override unless you are using QML where they have names. For plain QAbstractTableModel code you can deal with additional roles in data() & setData() methods without doing this name stuff.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        Lior
        wrote on last edited by
        #3

        After some searching on Google I understood that when overriding the

        QHash<int, QByteArray> CRowModel::roleNames() const
        

        it declares a new hash table,
        and it overrides the QAbstractItemModel hash table.

        your @JonB solution is the way to keep QAbstractItemModel with all the QT roles.

        1 Reply Last reply
        0
        • L Lior has marked this topic as solved on

        • Login

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