QAbstractTableModel DisplayRole stop working
-
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.
- if I override this function I can't use all the other roles that came with the QAbstractTableModel?
- can I explicitly add them to my hash table?
-
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.
- if I override this function I can't use all the other roles that came with the QAbstractTableModel?
- can I explicitly add them to my hash table?
@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 indata()
&setData()
methods without doing this name stuff. -
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.
-