viasant
6th August 2008, 17:54
QModelIndexList listModelIndex = selectionModel->selectedRows();
for (QModelIndexList::Iterator iter = listModelIndex.begin(); iter != listModelIndex.end (); ++iter, ++pChan) {
index = *iter;
row = index.row();
pChan->m_channel = modelChannel->data(modelChannel->index(row, 0), Qt::DisplayRole).toUInt();
pChan->m_isRecorded = modelChannel->data(modelChannel->index(row, 1), Qt::DisplayRole).toUInt();
pChan->m_isPrioritied = modelChannel->data(modelChannel->index(row, 2), Qt::DisplayRole).toUInt();
}
First I get the list of the selected rows; then I want to get the index of every row. However because the data have been sorted, so the getted row-index in Line L4 is not the one, which I want to get. I want get the index of the selected one in view by my eyes, not the one in the model in computer mem!
Maybe it is not easy to understand only by my above words. So you can try the example of QT4.4.X\examples\itemviews\addressbook. First you input 3 names and addresses one by one, such as <Alice, anywhere>, <Bring, anywhere> and <John, anywhere>, then you try to change the Alice' adress. You will find it can not to be changed!
for (QModelIndexList::Iterator iter = listModelIndex.begin(); iter != listModelIndex.end (); ++iter, ++pChan) {
index = *iter;
row = index.row();
pChan->m_channel = modelChannel->data(modelChannel->index(row, 0), Qt::DisplayRole).toUInt();
pChan->m_isRecorded = modelChannel->data(modelChannel->index(row, 1), Qt::DisplayRole).toUInt();
pChan->m_isPrioritied = modelChannel->data(modelChannel->index(row, 2), Qt::DisplayRole).toUInt();
}
First I get the list of the selected rows; then I want to get the index of every row. However because the data have been sorted, so the getted row-index in Line L4 is not the one, which I want to get. I want get the index of the selected one in view by my eyes, not the one in the model in computer mem!
Maybe it is not easy to understand only by my above words. So you can try the example of QT4.4.X\examples\itemviews\addressbook. First you input 3 names and addresses one by one, such as <Alice, anywhere>, <Bring, anywhere> and <John, anywhere>, then you try to change the Alice' adress. You will find it can not to be changed!