InfoModel类继承QAbstractListModel类,然后
QDeclarativeComponent component(m_qmlEngine, QUrl::fromLocalFile("..."));
QDeclarativeContext *context = new QDeclarativeContext(m_qmlEngine->rootContext());
QGraphicsObject *qml = qobject_cast<QGraphicsObject*>(component.create(context));
InfoModel *pageModel = new InfoModel;
context->setContextProperty("dataModel", pageModel);
这样把数据set给QML。
InfoModel类有个私有成员m_infos; 它的类型是QList<Info>(Info是一个结构体)。
struct Info
{
int id;
QString name;
int age;
};
请问这样一来,我该如何更新model的数据呢?比如我要更新pageModel里m_infos中某个元素的name,要怎么做?
------解决方案--------------------
我告诉你一个非常不幸的消息用QList 会内存泄露哦