I'm looking for a way to create a QModelIndex from a particular piece of data in my model. I can go from a QModelIndex to a data item via:
CustomData *data = static_cast<CustomData *>(modelIndex.internalPointer());
But I'm looking for an inverse function to go from:
QModelIndex *index = createIndex(data); // ??
I've implemented linkages between my data very similar to the simple tree model example (http://doc.qt.io/qt-5/qtwidgets-itemviews-simpletreemodel-example.html). My view displays the data correctly, but with considerable lag. I'd like to emit dataChanged(QModelIndex, QModelIndex) to see updates to the view instantly, since I think the lag is due to waiting for the view to update.
In the linked example, I'm trying to get from a TreeItem to its corresponding index in the QTreeModel.
You can't use traditional indicies because in the Model/View programming they don't stick around, unless you use:
QPersistentModelIndex
http://doc.qt.io/qt-5/qpersistentmodelindex.html#details
Also there are a lot of new paradigms introduced with the Model/View programming. The documentation on it and using it has a learning curve... read through it a few times and try using the examples bundled with Qt Creator that use them.
More about using
QPersistentModelIndex
http://doc.qt.io/qt-5/model-view-programming.html#using-model-indexes