• 6901阅读
  • 3回复

Model-View数据提取与更改 [复制链接]

上一主题 下一主题
离线whenever
 

只看楼主 倒序阅读 楼主  发表于: 2008-08-04
— 本帖被 XChinux 从 General Qt Programming 移动到本区(2011-01-02) —
与实际所要选择的数据不一致。
在选择后这里显示为排序后的索引值,但是在modelChannel中数据 并未重新排序,造成model与显示的数据index不一致,因而在根据显示的index向modex采集数据时,造成数据非想要的数据。

在addressbook的示例里面同样存在这个问题,只能编辑最后一个加入的address,因为每一次row都是0,如果每页只有一条数据。
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();
}

不知道大家如何获取相应数据的?
离线foxyz

只看该作者 1楼 发表于: 2008-08-04
1.代码太少
modelChannel是什么?selectionModel又是什么?
2.我从来没有碰到过有所谓不对应的情况出现.
离线whenever

只看该作者 2楼 发表于: 2008-08-04
在addressbook的示例里面同样存在这个问题,只能编辑最后一个加入的address,因为每一次row都是0,如果每页只有一条数据。
你可以使用\Qt\4.4.0\examples\itemviews\addressbook这个例子试一次,就知道啦。用加入几组数据,然后试图修改某组数据
离线whenever

只看该作者 3楼 发表于: 2008-08-07
QModelIndexList listModelIndex = selectionModel->selectedRows();
for (QModelIndexList::Iterator iter = listModelIndex.begin(); iter != listModelIndex.end(); ++iter, ++pChan) {       
index = *iter;                   
index = channelWindow->proxyModel->mapToSource(*iter);
index = channelWindow->proxyModel->mapToSource(*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();
}

这样就好了!
快速回复
限100 字节
 
上一个 下一个