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 April 2025
When you implement a model, it is worthwhile remembering that one day an intern, with far less experience than you, might implement a proxy model which sits on top of your model and acts as the view. This proxy model might be broken in ways you couldn't even imagine, so better check that the index provided are actually referring to valid data in your model.
This episode discusses this in details, and offers you a simple library with all checks needed.
Chapters:
00:00 Welcome
00:26 Why is this important?
02:35 Over to the QWAM episode
03:36 The broken example
05:48 Hint to what is wrong
07:20 What is the cure?
08:05 What can I do to be more safe?
09:10 Qt 5.11 - checkIndex
12:39 CHECK_ macros
14:56 QAbstractProxyModel::headerData calling index for an invalid row
Links:
* QWAM: Communicating between view and model: https://youtu.be/q6eOEz_UfTI?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI
* Blog post on checkIndex: https://www.kdab.com/new-in-qt-5-11-improvements-to-the-model-view-apis-part-1/
* Categorized logging: https://www.youtube.com/watch?v=f12lUvbdj2U&list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI&index=52&t=639s
The example code showcased in this video is available here:
https://github.com/KDABLabs/kdabtv/tree/master/Programming-With-Qt-Widgets/modelview
All 'Introduction to Qt Widgets - Module 1' videos: https://www.youtube.com/playlist?list=PL6CJYn40gN6hgf7zCKF2Rv9Y0WoN8RVGf
All 'Introduction to Qt Widgets - Module 2' videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6j_c41CFMprvg9EiWz0WdSy
All 'Introduction to Qt Widgets - Module 3' videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6hWZO_viEf1rfjgk4E6SCKd
All 'Introduction to Qt Widgets - Module 4' videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6iXUNQMb2GkEjV_oK6Xid9-
All 'Introduction to Qt Widgets - Module 5' videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6h1tsLAETdrrFlsVMeYpiHI
All 'Introduction to Qt Widgets - Module 6' videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6jIsRYriqN70V83t_mdDZHT
All 'Introduction to Qt Widgets - Module 7' videos: https://www.youtube.com/playlist?list=PL6CJYn40gN6hHyqD9ZxUqpd14LoHvadN7
All 'Introduction to Qt Widgets - Module 8' videos: https://www.youtube.com/playlist?list=PL6CJYn40gN6iCb8g5NSfVqX0JRFzFnxak