QML ListModel.onDataChanged arguments

白昼怎懂夜的黑 提交于 2019-12-12 04:23:17

问题


I was wondering what kind of data I can use to handle a dataChanged-signal in a QML ListModel. I found out that it has three arguments, two of which are QModelIndices and one is a QVariant(...).

So from the first two (which seems to be the same?) I can get the row, column (which is supposed to be 0), the model itself and uhm... stuff

But why do I get it twice? And what is the content of the third? It is not null, but I haven't found a property I could use to retrieve some useful data from it.


回答1:


A ListModel implementsQAbstractItemModel, the dataChanged signal you are seeing is the one defined in this class : void QAbstractItemModel::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int> ())

The 2 first parameters tell us that all data between the first and second indexes are changed. The 3rd parameter is a list of roles where the data has changed, if the list is empty it means the data at all roles has potentially been changed.

In your case the first and second indexes are the same because only one row is changed at a time.



来源:https://stackoverflow.com/questions/39874958/qml-listmodel-ondatachanged-arguments

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!