在 TableView 中用这种方式赋值,似乎将 C++ 对象与 QML 对象绑定在一起了,所以会被自动释放掉
问题码
Component.onCompleted: {
var work = tableView.model.getItem(styleData.row)
work.onValueChanged.connect(setText)
text = work.mCurrentValue
}
function setText(val) {
text = val
}
Note: Avoid storing any state inside a delegate. If you do, reset it manually on receiving the TableView::reused signal.
If an item has timers or animations, consider pausing them on receiving the TableView::pooled signal. That way you avoid using the CPU resources for items that are not visible. Likewise, if an item has resources that cannot be reused, they could be freed up.
If you don't want to reuse items or if the delegate cannot support it, you can set the reuseItems property to false.
看这段的意思就是,对于那些不可以重复的内容, TableView 自带的 reused 机制可能会将其释放掉,需要显式声明 false
Reusing items
我的处理方案
property var workObj: tableView.model.getItem(styleData.row)
text: workObjT !== null ? workObjT.mCurrentValue : ""
用这种方式代替
原因:
没有在 import QtQuick.Controls 1.4 版本中找到相关描述