Search code examples
c++qtforeachqhash

loop through nested QHash with foreach


I have QHash<QString, QHash<quint64, QElapsedTimer*> myNestedQHash; and when I try

foreach (QHash<quint64, QElapsedTimer*>  stat, myNestedQHash.values(someStr))

I get

error: macro "Q_FOREACH" passed 3 arguments, but takes just 2

Isn't it possible to loop on nested QHash they way I did?


Solution

  • why not using

    for (QHash<QString, QHash<quint64, QElapsedTimer*>::iterator it = myNestedQHash.begin(); it != myNestedQHash.end(); ++it) 
    {...}
    

    instead? i think Q_FOREACH will create a copy, so it will be better performance as well...

    /edit:

    the foreach is just a definition for the Q_FOREACH macro ... so the compiler sees it and it will accept 2 values. since you have a additional comma in it, it will see 3 arguments. you will find all infos here.