SetRoleNames in Qt 5.0.1
I try to use some code...
ListModel::ListModel(ListItem* prototype, QObject *parent) :
but QAbstractListModel don't contains function setRoleNames in Qt 5.0.1 libraryes, why and how to fix. I need to use some model from c++ and show it in QML
[Please wrap code in @ tags -- mlong]
The problem is that ListModel is intended for simple lists without roles. You just have to use a more appropriate model that supports roles such as QStandardItemModel. Just look at this for a full example on how to use role names with C++:
QStandardItemModel not contains method setRoleNames too. In example http://www.developer.nokia.com/Community/Wiki/Using_QStandardItemModel_in_QML i download file.
RoleItemModel::RoleItemModel(const QHash<int, QByteArray> &roleNames)
when compile i have error:
C3861: setRoleNames identificator not found
Just read the example I sent you. It shows you exactly how to assign role names to a model.
"There is no magic in RoleItemModel - it merely calls QAbstractItemModel::setRoleNames, which happens to be a protected member of QAbstractItemModel."
QtCreator intellisanse show that.
razario. That is a protected member. You cannot call it unless you subclass the model.
if it's protected I herit QAbstractItemModel and I try to use it in child class:
but it's not contains it.
I open qstandarditemmodel.h and that's NOT contains this methodб сlass inherits.
Decided no more setRoleNames in Qt 5 methods. I need to override roleNames
sam_dev last edited by
I have tried following the above comments but still I'm not getting the desired results, I'm not able to replace setRoleNames() with roleNames().
Can someone give an example or a code snippet which will show how we can port setRoleNames() API in Qt5 by overriding roleNames() API?