[Development] Qt 5 types under consideration for deprecation / removal in Qt 6
Kevin Kofler
kevin.kofler at chello.at
Wed Jun 5 11:47:15 CEST 2019
Samuel Gaist wrote:
>> On 5 Jun 2019, at 00:39, Kevin Kofler <kevin.kofler at 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
More information about the Development
mailing list