Edit element inside QAbstractListModel
-
I'm using the ListModel presented in this "tutorial":http://cdumez.blogspot.com/2010/11/how-to-use-c-list-model-in-qml.html
Now I want to change some properties of an item of the ListView when you're clicking on it.
In the tutorial this would be simply calling the function setPrice().
But how can I call this function and how can Qt know which element I want to change?I think I missing the forest through the trees. I hope you can help me.
-
In my delegate I'm using the onClicked-Event of a MouseArea and tried the following
@setPrice(3)@I don't know what's going wrong.
I used the Q_INVOKABLE macro to make the function visible for QML.The error from the compiler is
Can't find variable: setName
without brackets..so QML doesn't recognize it as a function -
Has anyone an idea on how to solve this problem.
I simply want to modify an item of my QAbstractItemModel displayed in a ListView in QML.
The funciton is written and should work but I don't know how to call it.Maybe there is an other solution I don't see?
-
I found out that I have to define the functions
@
setData(int row, const QString & field_name, QVariant new_value)
Qt::ItemFlags flags( const QModelIndex & index ) const
@Then it should be posible to call the function like this in QML
@ListView.view.model.setData(index, field, value)@If someone already has written these functions (especially with QList data) it would be great if you would share some code snippets.