// 最终的结果在mapText参数里
void fetchChild(QAbstractItemModel *_model,
QModelIndex &parentIndex,
QStringList &stackText,
QMap<QModelIndex, QString> &mapText)
{
stackText.push_back(parentIndex.data().toString());
if (_model->hasChildren(parentIndex))
{
for (int i = _model->rowCount(parentIndex) - 1; i > -1; i--)
{
QModelIndex idx = _model->index(i, 0, parentIndex);
fetchChild(_model, idx, stackText, mapText);
}
}
else
{
if (parentIndex != QModelIndex())
{
mapText[parentIndex] = stackText.join();
}
}
stackText.pop_back();
}
fetchChild(_model, QModelIndex(), stackText, mapText);