A map provides quick access based upon the key (the first argument).
So, yes, if you want to know if a value exists (the second argument), you would need to iterate over the map values:-
bool ValueExists(const QMap<int, QString> map, const QString valExists)
{
QList<QString> valuesList = map.values(); // get a list of all the values
foreach(QString value, valuesList)
{
if(value == valExists)
{
return true;
}
}
return false;
}
To simplify the code, we can also use the values' contains() method, which internally will iterate over the values, as above.
map.values()
. Just usemap.contains(valExists);
– Tews