【发布时间】:2023-03-04 09:33:02
【问题描述】:
我复制了 Qt 示例动物 qabstractitemmodel 并尝试在 QML 中显示它并更改值。我已经在模型中添加了一个函数来做到这一点
Q_INVOKABLE void change()
{
m_animals.first().m_size="newValue";
// setData(this->index(0), "newValue", SizeRole); //always returns false, has no effect if uncommented
qDebug() << this->data(this->index(0), SizeRole); //returns correctly new value as set in previous uncommented line
emit dataChanged(this->index(0), this->index(this->rowCount()), {SizeRole}); // the value in QML is not updated at any point
}
为什么 QML 中的值没有更新?
我已经上传了完整的示例
谢谢。
【问题讨论】:
标签: c++ qt qml qt5 qabstractitemmodel