QModelIndex index = model->index(0, 2); // get an index at row 0, column 2 int column = index.column(); // returns 2
QModelIndex parentIndex = model->index(0, 0); for (int i = 0; i < model->rowCount(parentIndex); i++) { QModelIndex childIndex = model->index(i, 1, parentIndex); // get a child index at row i, column 1 int column = childIndex.column(); // returns 1 }This code snippet iterates through the child rows of an index at row 0 and column 0 in the model. For each child row, an index is retrieved at column 1 using the index method with the parentIndex as a parameter. The column method is then called on the child index object to return the column number. The above examples are part of the Qt library.