Using strong_typedef with Qt for Improved Safety
Integers and strings can be used as data types for many different things: user id's, project id's, employee names, and account names, to name just a few.
Doing so, however, also means that you run the risk of confusing project ids with user ids or employee names with account names, with your compiler helplessly watching while you shoot yourself in the foot - after all to your compiler it is just integers and strings.
In this episode, I'll show one cure to this, namely a class you can wrap around your integers or strings to make them unique. I'll of course discuss the integration with Qt.
https://github.com/anthonywilliams/strong_typedef
If you have a Java background, a C++98 background or similar your finger memory may reach for the subclassing tool in your toolbox when faced with a problem.
In modern C++, there are many different ways to solve problems. In this episode, I'll show an example for which subclassing indeed isn't the right tool.
The example code showcased in this video is available here: https://github.com/KDAB/kdabtv/tree/master/Qt-Widgets-and-more/strong_typedef
Qt DevCon is a conference for the Qt developer community and focuses exclusively on developer topics. This year, it will will take place in Berlin, Germany from 14th to 15th June 2022: https://www.qtdevcon.com/
QtDevCon programme: https://www.qtdevcon.com/tuesday-14th-june/
QtDevCon training day info: https://www.qtdevcon.com/training-day/
Registration: https://www.qtdevcon.com/tickets/
All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI
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.
Every month our newsletter is featuring technical blogs on Qt, C++ and 3D topics: https://www.kdab.com/development-resources/sign-up-for-our-newsletter/
About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more. https://www.kdab.com/software-services
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++.
Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/
We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/
19