【发布时间】:2018-11-20 09:38:29
【问题描述】:
我有一个 QVector<CConfiguration*> 列表作为我的 ListView 的数据源。我动态创建这些对象并将其设置为 ContextProperty。
qmlRegisterUncreatableType<CConfiguration>("DataObjects", 1, 0, "Configuration",QStringLiteral("Configuration should not be created in qml."));
configs.load();
engine.rootContext()->setContextProperty(QStringLiteral("configurations"), &configs);
到目前为止一切都很好。 ListView 显示所有数据都很好。 当我现在尝试访问单个数据对象时。
var item = configurationsModel.get(3);
这个对象后来被破坏,当我滚动 LIstView 后给我一个 SIGSEGV。 get 方法返回一个 CConfiuration*
感谢您的想法或帮助
【问题讨论】:
-
我鼓励您实施适当的数据模型。
-
@dtech,什么是“适当的数据模型”?
-
您能否更具体地了解“正确的数据模型”?我总是很高兴能学到新东西。