I solved the problem by using role name as Qt::display in my qml file.
import QtQuick 2.0
//![0]
ListView {
width: 100; height: 100
model: myModel
delegate:
Item{
Rectangle {
height: 25
width: 100
Text { text: display }
}
}
}
QVariant QStringListModel::data(const QModelIndex &index, int role) implemented for Qt::DisplayRole only hence it was not able to show the items.
QVariant QStringListModel::data(const QModelIndex &index, int role) const
{
if (index.row() < 0 || index.row() >= lst.size())
return QVariant();
if (role == Qt::DisplayRole || role == Qt::EditRole)
return lst.at(index.row());
return QVariant();
}
But with same I’m hit with another problem i.e. my qml shows only the lat item. Any idea how display the entire list?
↧