SetRoleNames in Qt 5.0.1
-
I try to use some code...
@
ListModel::ListModel(ListItem* prototype, QObject *parent) :
QAbstractListModel(parent), m_prototype(prototype)
{
setRoleNames(m_prototype->roleNames());
}
@
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++:
http://www.developer.nokia.com/Community/Wiki/Using_QStandardItemModel_in_QML -
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)
{
setRoleNames(roleNames);
}
@
when compile i have error:
C3861: setRoleNames identificator not found -
-
http://www.picshare.ru/view/1253145/
QtCreator intellisanse show that. -
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?