Search code examples
c++qtqmap

QMap iterate foreach


Is it possible to iterate through qmap when key and value is a pointer with foreach?

I always get the error: decltype cannot resolve address of overloaded function

template <typename T, typename T1>
bool func(T1* subject, QMap<T*,T1*>* map)
{
    //...
    foreach (T1* a, map->values) {

    }

thank you for helping me


Solution

  • As Mike pointed out, you need to call map->values() before foreach would even work normally.

    foreach operates on references, and QMap::values() returns a list of them. This would work:

    foreach (T1 a, map->values()) {
        if (a == *subject)
            ...
    }