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
28 April 2021
In your code, you will likely find numerous places where you go from an enum to a QString and back. This could, for example, be code where you serialize your data.
The code might very well look like this:
if (value == ExampleEnum::Foo)
return "Foo";
else if (value == ExampleEnum::Bar)
return "Bar";
~~~
But there is a smarter way to do it, using Qt's introspection facilities. Watch here to learn that trick.
The example code showcased in this video is available here:
https://github.com/KDAB/kdabtv/tree/master/Qt-Widgets-and-more/EnumConverter
All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI