PDA

View Full Version : Traversing QTableView



junxuan
31st July 2009, 17:10
Due to a school project, i wanted to do a small database program with Qt. After setting up a QTableView and its QStandardItemModel, im wondering how i can traverse for the values as i need to save the values into a text file. Preferably it traverses row by row. Thx for any info.

shentian
31st July 2009, 17:24
The data displayed in the QTableView is actually stored in its model. Use:



QAbstractItemModel* model = tableView->model();
for (int row = 1; row < model->rowCount(); ++row)
{
for (int column = 1; column < model->columnCount(); ++column)
{
QVariant itemData = model->index(row, column).data();
// process data ...
}
}

junxuan
1st August 2009, 19:44
Thx for the help.
Cheers.