我需要遍历 QMultiHash
并检查与每个键对应的值列表。我需要使用可变迭代器,这样我就可以从哈希中删除符合特定条件的项目。 The documentation没有解释如何访问所有的值,只是第一个。此外,该 API 仅提供 value()
方法。如何获取特定键的所有值?
这就是我想要做的:
QMutableHashIterator<Key, Value*> iter( _myMultiHash );
while( iter.hasNext() )
{
QList<Value*> list = iter.values(); // there is no values() method, only value()
foreach( Value *val, list )
{
// call iter.remove() if one of the values meets the criteria
}
}
最佳答案
对于 future 的旅行者,这就是我为了继续使用 Java 风格的迭代器而最终做的事情:
QMutableHashIterator<Key, Value*> iter( _myMultiHash );
while( iter.hasNext() )
{
// This has the same effect as a .values(), just isn't as elegant
QList<Value*> list = _myMultiHash.values( iter.next().key() );
foreach( Value *val, list )
{
// call iter.remove() if one of the values meets the criteria
}
}
关于c++ - 如何遍历 QMultiHash 中的所有 values(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17497598/