QModelIndex index = model->index(row, col, parent); if (index.isValid()) { MyDataModel* dataPtr = static_cast(index.internalPointer()); // access dataPtr }
QModelIndexList indexList = view->selectionModel()->selectedIndexes(); for (const QModelIndex& index : indexList) { MyDataModel* dataPtr = static_castIn this example, we are working with multiple selected items in a view. We retrieve a QModelIndexList of the selected items, and then loop through each index, using the internalPointer method to retrieve the data model pointer for each item. The Qt framework/library.(index.internalPointer()); // access dataPtr }