PDA

View Full Version : how to add model to different model-delegate



stevocz
16th February 2018, 11:48
Hi.
i have ListView with model in main.qml where is loaded second qml with data. But when i want data from second model they still looking into first model (groupModel) in main.qml. How to get data from itemModel?
model is in c++. it finish with ReferenceError: datafromItemModelis not defined becouse datafromItemModel is defined in itemModel and he still looking into groupModel

here is little example:

main.qml


ListView {
id: listView
anchors.fill: parent
model: groupModel

delegate: Loader {
source: fileName // fileName from groupModel data
}
}


item.qml


GridView {
model: itemModel

delegate: Rectangle {
Text {
text: datafromItemModel
}
}
}


c++ code


QVariant MainModel::data(const QModelIndex & index, int role) const
{
const ItemModel * itemModel= mainDatas.at(index.row());
switch (role)
{
case fileNameRole:
return QString("item.qml");
case itemModelRole:{
return itemModel;
}
default:
return QVariant();
}
}

wysota
25th February 2018, 09:05
Do you mean that one model serves data which is instances of the other model?