My Qt desktop app was built on the editabletreemodel sample application. In the sample application in treemodel.cpp there is a mthod called getItem() which takes a QModelIndex as a parameter and returns a pointer to a TreeItem.
This is what the method looks like:
TreeItem *TreeModel::getItem(const QModelIndex &index) const
{
if (index.isValid()) {
TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
if (item)
return item;
}
return rootItem;
}
I would like to do the reverse - that is return a QModelIndex for a given TreeItem.
How can I do this?
Difficult... very difficult. And directly not possible. And if you use the TreeItem as in the Qt example code you are out of luck. What you can do is:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With