Sign up for the KDAB Newsletter
Stay on top of the latest news, publications, events and more.
Go to Sign-up
Find what you need - explore our website and developer resources
23 March 2023
This is Giuseppe's commentary edition. It's advised you watch Jesper's version first, which can be found here:
https://www.youtube.com/watch?v=f7dlD10bhiI
Iterating over the values of a QMap or QHash traditionally happened by iterating over the key and then looking up the value using that key. Besides that this requires an additional lookup, it is also a bit clumsy.
A much more elegant solution to the problem is structured bindings - a feature introduced in C++17. To use this out of the box, you need Qt 6.4 but this episode shows how you relatively easily can enable it for older Qt versions too.
Links:
* https://www.kdab.com/qt-range-based-for-loops-and-structured-bindings
* https://en.cppreference.com/w/cpp/language/structured_binding
The example code showcased in this video is available here: https://github.com/KDAB/kdabtv/tree/master/Qt-Widgets-and-more/ranges
All QML tips and tricks videos : https://www.youtube.com/playlist?list=PL6CJYn40gN6jWHP5krsQrVGyYtKh3A3be
All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI