QML ListModel.onDataChanged 参数 [英] QML ListModel.onDataChanged arguments

查看:40
本文介绍了QML ListModel.onDataChanged 参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我可以使用什么样的数据来处理 QML ListModel 中的 dataChanged 信号.我发现它有三个参数,其中两个是 QModelIndices,一个是 QVariant(...).

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(...).

所以从前两个(似乎是一样的?)我可以得到行、列(应该是 0)、模型本身和呃......东西

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.

推荐答案

A ListModel 实现QAbstractItemModel,您看到的 dataChanged 信号是此类中定义的信号:void QAbstractItemModel::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles = QVector())

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.

这篇关于QML ListModel.onDataChanged 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆