Samuel Gaist wrote: >> On 5 Jun 2019, at 00:39, Kevin Kofler <kevin.kof...@chello.at> wrote: >> Can't we just add a keySet() method (named after the Java one that does >> something similar) that returns a wrapper object that just forwards >> begin() to the map's keyBegin() etc.? Then you could just write something >> like: for (auto key : map.keySet()) >> and it should do conceptually the same as: >> for (auto key : map.keys()) >> but without ever having to build the list of keys as a list. >> >> Or, probably even more efficiently, add cursorBegin() etc. iterator >> methods that return iterators returning key-value pairs as QPair, and a >> cursorSet() that returns a wrapper object for them like keySet() above. >> Then: for (auto cursor : map.cursorSet()) >> would get you key-value pairs, wouldn't it? > > Since Qt 5.10, QHash and QMap have something for that: > > https://doc.qt.io/qt-5/qhash.html#keyValueBegin > https://doc.qt.io/qt-5/qhash.html#keyValueEnd > > And their corresponding const versions.
So only the keyValueSet() wrapper object for ranged for (that I described above) is missing. > Note that the iterator returns a std::pair. Ewww, why? Qt APIs should return Qt classes, not STL classes! Kevin Kofler _______________________________________________ Development mailing list Development@qt-project.org https://lists.qt-project.org/listinfo/development