How do you get the data from your model (sub-classed from QAbstractItemModel
) outside of the delegate using QML?
I tried it like this:
Identities {
id: identities_model
}
...
console.log(identities_model[0].email)
but I get an error:
TypeError: Cannot read property 'email' of undefined
My data()
method is defined like this:
QVariant Identities::data(const QModelIndex &index, int role) const {
int row_num;
row_num=index.row();
if (role==EmailRole) {
QList <QString> qlist;
qlist=identities_map.keys();
if (row_num>=qlist.size()) return (QVariant());
return QVariant(qlist.at(row_num));
}
if (role==PasswordRole) {
QList <QString> qlist;
qlist=identities_map.keys();
if (row_num>=qlist.size()) return (QVariant());
Identity *identity;
identity=identities_map.value(qlist.at(row_num));
return QVariant(identity->password());
}
if (role==Qt::DisplayRole) {
return(QVariant());
}
}
I tried to debug (put some breakpoints) but couldn't intercept any call to Identities::data()
or Identities::index()
towards my model from QML. How should I access data in my model outside of the delegate? (specific row, specific role) When I use delegates, my model works perfectly fine.