return m_size;
}
-//![0]
AnimalModel::AnimalModel(QObject *parent)
: QAbstractListModel(parent)
{
- QHash<int, QByteArray> roles;
- roles[TypeRole] = "type";
- roles[SizeRole] = "size";
- setRoleNames(roles);
}
-//![0]
void AnimalModel::addAnimal(const Animal &animal)
{
return QVariant();
}
+//![0]
+QHash<int, QByteArray> AnimalModel::roleNames() const {
+ QHash<int, QByteArray> roles;
+ roles[TypeRole] = "type";
+ roles[SizeRole] = "size";
+ return roles;
+}
+//![0]
+
\endtable
Here is an application with a QAbstractListModel subclass named \c AnimalModel
-that has \e type and \e size roles. It calls QAbstractItemModel::setRoleNames() to set the
+that has \e type and \e size roles. It reimplements QAbstractItemModel::roleNames() to set the
role names for accessing the properties via QML:
\snippet examples/quick/modelviews/abstractitemmodel/model.h 0