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
7 June 2022
One of the most complex things in Qt's model/view framework is the implementation of proxy models.
In this episode, I'll show an almost complete implementation of a proxy model which reverses its rows but, at the same time, also gives hints for where and when you can cut corners.
Links:
* Proxy model collection in KDToolbox: https://github.com/KDAB/KDToolBox/tree/master/qt/model_view
* Proxy model collection from KDE: https://api.kde.org/frameworks/kitemmodels/html/index.html
* Episode on CHECK_index: https://www.youtube.com/watch?v=brINmY_4X60
* Episode on unit testing: https://www.youtube.com/watch?v=N4pvvCToogM
0:00 Introduction
2:06 Implementing the QAbstractProxyModel API
9:00 Running the code without listening to signals
12:13 It is OK to not go further than this!
14:17 emitting beginResetModel and endResetModel is sometimes enough
16:38 listening to dataChanged signal
19:01 rowsAboutToBeInserted, rowsInserted, ... signals
22:14 headerDataChanged, modelReset, modelAboutToBeReset signals
23:08 Unit testing the model
27:26 The MasteSpy class - why is it needed
29:31 The MasterSpy class - how is it used
31:19 Careful proxy models may crash!
The example code showcased in this video is available here: https://github.com/KDAB/kdabtv/tree/master/Qt-Widgets-and-more/ReverseRowsProxyModel
All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI