filmov
tv
Converting Enums to and from Strings

Показать описание
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:
All Qt Widgets and more videos:
About the host:
The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.
About KDAB:
KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.
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:
All Qt Widgets and more videos:
About the host:
The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.
About KDAB:
KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.
Комментарии