QModelIndex index = model->index(0, 0); if (index.isValid()) { QString data = model->data(index).toString(); qDebug() << "Data at index (0,0):" << data; }
for (int row = 0; row < model->rowCount(); row++) { for (int column = 0; column < model->columnCount(); column++) { QModelIndex index = model->index(row, column); if (index.isValid()) { QString data = model->data(index).toString(); qDebug() << "Data at index (" << row << "," << column << "):" << data; } } }In this example, we loop through all the cells in the data model and retrieve the data at each index before displaying it. We check whether each index is valid before retrieving its data. The QModelIndex class and its methods are part of the Qt Core library.