QAbstractListModel: How to use insertRows/removeRows if data is managed outside
-
Hi,
I want to make a QAbstractListModel which is a member of a class. Inside the model I would like to store a pointer to the actual data:
std::vector<double> * _pos;
I understand how to implement
rowCount
anddata
but I wonder what I should do withinsertRows
andremoveRows
if the contents of_pos
are managed outside the model.The implementation of my
data
function looks like this:case Position: return QVariant::fromValue(_pos->at(index.row()));
-
Hi,
How exactly is that data managed ?
Where does it come from ? -
@maxwell31 said in QAbstractListModel: How to use insertRows/removeRows if data is managed outside:
Inside the model I would like to store a pointer to the actual data:
How does your model know when the data has changed externally?
@maxwell31 said in QAbstractListModel: How to use insertRows/removeRows if data is managed outside:
I wonder what I should do with
insertRows
andremoveRows
if the contents of_pos
are managed outside the model.It should either
- Modify the data and return
true
, OR - Do nothing and return
false
- Modify the data and return
-
Well, maybe it would be bad design anyway, but this is how I thought it could be:
I have a c++ class, which has e.g. a std::vector<double> which I want to expose to qml via a QAbstractListModel. In this backend class, items can be added, modified, and deleted. I thought that instead of mirroring the vector inside my QAbstractListModel I could simply use the pointer to this vector in the QAbstractListModel, and call the necessary signals of QAbstractListModel in the backend class
-
That's correct. Now the question are:
- Where is that backend class modified in your code ?
- What will modify the content of that vector ?