问题
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