[Solved] How to iterate a QList<QMap<QString,QString>> list ?
-
Hi,
I'd like to iterate a QList<QMap<QString,QString>> list, but with foreach I obtain an error.
I tried this with no result:
@QList<QMap<QString,QString>> myList;
foreach(QMap<QString,QString> singleItem, myList) {
//code here
}@Compiler error are:
C2275 and C2065
Thanks in advance.
-
Please read the documentation of foreach! An explanation an a solution to your problem is already there.
"Link":http://qt-project.org/doc/qt-5/containers.html#the-foreach-keyword.
-
did you try the native c++11 for-each loop?
it should work without a typedef, just as an alternative if you have access to c++11:
@
QList<QMap<QString,QString>> myList;for(QMap<QString,QString>& singleItem : myList) {
//code here
}
@
I just used a reference (&) for the "singleItem". -
Hi,
Just to be sure you won't get bitten, you know that takeFirst removes the element ? Are you sure it's the behavior you want ?