[Interest] Understanding QQmlListModel::sync()

Ian Trick itrick at bardel.ca
Mon Oct 15 20:56:56 CEST 2018


I've been looking at QQmlListModel::sync() (found in
qtdeclarative/src/qml/types/qqmllistmodel.cpp) (looking at v5.11) for
quite some time and haven't been able to figure out how it can work.
I'm still trying to come up with a terse explanation of how I think
the function behaves and a circumstance where it fails to do the
correct thing.

In the mean time, it appears to me that `beginInsertRows()` and
`beginMoveRows()` are called after the underlying model is changed. I
thought that wasn't allowed.

> When reimplementing insertRows() in a subclass, you must call this function before inserting data into the model's underlying data store.
https://doc.qt.io/qt-5/qabstractitemmodel.html#beginInsertRows

I assume the same about `beginMoveRows()` but it's not actually clear
to me. However `endMoveRows()` does say:

> When implementing a subclass, you must call this function after moving data within the model's underlying data store.
https://doc.qt.io/qt-5/qabstractitemmodel.html#endMoveRows

Presumably that doesn't mean "any time before" but specifically
between beginMoveRows and endMoveRows.  And, as I understand it, it
doesn't matter that it's in a subclass except in so far as the
subclass tends to be the caller and has access to the protected
underlying data store.

Am I misunderstanding anything here so far?

Also, are there tests for this? The only test I could find related to
this had to do
with making sure some function was only callable from a QML worker script.



More information about the Interest mailing list