1
使用多个数据模型的列表视图我想在2个列表视图使用2种型号,但第二个列表不填充像第一个。 ,我已经使用作为代码如下:QML-如何在QML
Q_DECL_EXPORT int main(int argc, char *argv[])
{
QScopedPointer<QApplication> app(createApplication(argc, argv));
MyModel myModel;
myModel.addPrimaryData(ModelItem(1, "Apple"));
myModel.addPrimaryData(ModelItem(2, "Orange"));
myModel.addPrimaryData(ModelItem(3, "Banana"));
MyModel myModel2;
myModel2.addSecondaryData(ModelItem(1, "Apple2"));
myModel2.addSecondaryData(ModelItem(2, "Orange2"));
myModel2.addSecondaryData(ModelItem(3, "Banana2"));
QDeclarativeView declView;
QDeclarativeContext *declContext = declView.rootContext();
declContext->setContextProperty("myModel", &myModel);
declContext->setContextProperty("myModel2", &myModel2);
declView.setSource(QUrl("qml/MyDemo/main.qml"));
declView.show();
return app->exec();
}
如上显示,我已经建立2种型号即基于myModel和myModel2和用于在QML 2个Listy观。
ListView1的使用模型基于myModel和ListView2使用模型myModel2。但myModel2数据不在列表中显示。
此的任何具体原因。请回复你的想法。
,我已经使用的QML代码如下:
ListView {
id:firstListView
model: myModel
delegate: Item{
id: firstDelegate
Text {
text: name
color: "white"
}
}
}
ListView {
id: secondListView
model: myModel2
delegate: Item{
id: secondDelegate
Text {
text: name
color: "white"
}
}
}
你应该张贴QML代码。 – JuliusG
尽管事实上您使用了两个ListView项目,但您并未提供有关模型的内部信息以及您在QML中使用它们的方式的任何信息。给任何受过教育的答案带来太多的不确定性。 – sebasgo
我已更新帖子,请重新访问并提供您的意见。 – user1182217