QStandardItemModel 遍历勾选的项
rowCount()不能传入 m_model->index(0, 0)根节点,无法获取行数;
不传,或者传入一个空QModelIndex对象,可以获取到第一级节点的数量;
QMap<QString,QVariantMap> mapSelectVideo; int rootRowCount = m_model->rowCount(); for (int i= 0;i<rootRowCount;i++) { QModelIndex rootIndex = m_model->index(i, 0); RecursiveFindCheckedVideo(rootIndex, mapSelectVideo); }
void SelectVideoTree::RecursiveFindCheckedVideo(QModelIndex& parent, QMap<QString, QVariantMap>& mapSelectFile) { if (parent.isValid()) { int rowCount = m_model->rowCount(parent); for (int i = 0; i < rowCount; ++i) { QModelIndex childIndex = m_model->index(i, 0, parent); QStandardItem* pItem = m_model->itemFromIndex(childIndex); if (pItem) { QVariantMap info = pItem->data().toMap(); if (info.value("type") == "2")//视频文件 { mapSelectFile.insert(info.value("location").toString(), info); } else { RecursiveFindCheckedVideo(childIndex, mapSelectFile); // 递归遍历子项 } } } } }标签:info,遍历,parent,rowCount,QStandardItemModel,勾选,int,model From: https://www.cnblogs.com/bclshuai/p/18196665