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 September 2021
You want enum class over just enum, right? That is, however, a bit troublesome with Qt's model/view framework, where you often use int. Consider this code:
In Header file:
enum class Column {Name, Age}
In source file:
QVariant MyModel::data(const QModelIndex& Index) {
~~~
switch (static_cast⋖Column⋗(index.column())) {
case Column::Name: return ~~~~~~
}
This episode will introduce a few helpers that will make your life much easier.
The example code showcased in this video is available here: https://github.com/KDAB/kdabtv
All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI