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
}
}
ListView {
id: listView
anchors.fill: parent
model: groupModel
delegate: Loader {
source: fileName // fileName from groupModel data
}
}
To copy to clipboard, switch view to plain text mode
item.qml
GridView {
model: itemModel
delegate: Rectangle {
Text {
text: datafromItemModel
}
}
}
GridView {
model: itemModel
delegate: Rectangle {
Text {
text: datafromItemModel
}
}
}
To copy to clipboard, switch view to plain text mode
c++ code
{
const ItemModel * itemModel= mainDatas.at(index.row());
switch (role)
{
case fileNameRole:
case itemModelRole:{
return itemModel;
}
default:
}
}
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();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks