Since Qt 5.6 we can finally write code like this:
ListView {
id: list
model: MyModel
delegate: TextInput {
text: display
onEditingFinished: {
model.edit = displayText
}
}
i.e. model.edit
will call MyModel
's setData()
with Qt::EditRole
and display value from the TextInput
. Great, was headache for a long time.
However even if using QAbstractItemModel
is the recommended practice for more complex C++ based models I still have the feeling that all of it is meant only for read only models, i.e. that a qml view can read the number of rows, columns etc but it was never meant as a way for adding or removing rows (for clean implementation of QAbstractItemModel::setData
the row must be already present).
It feels really dirty to reimplement all the insert/remove functions with Q_INVOKABLE and qml's ListModel
is far too simple for anything serious.
What would you recommend for a qml based widget which should add/remove rows, edit items and yet have a C++ model?