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
10 March 2021
In my code I have a lot of custom classes I use with model/view, including Money, PercentageValue, TimeValue just to name a few.
For years I've written code like this in my data methods of QAbstractItemModel subclasses:
return QVariant::fromValue(cost); // cost is an instance of the class Money
In this short video you will learn a very simple trick to avoid this.
The example code showcased in this video is available here:
https://github.com/KDAB/kdabtv/tree/master/Qt-Widgets-and-more/CustomTypesAndVariants
and https://github.com/KDAB/kdabtv/tree/master/Qt-Widgets-and-more/VariantConverters
All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI