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
14 April 2022
Designing API's is hard work with lots of traps. Even worse is the situation when you later maintain the code and just need a function to behave slightly different in different situations.
I'll start this episode by bashing Qt 3, where you could write update(false). What does that mean? Do not update?
I'll take this to the extreme and suggest that you ban boolean arguments to functions altogether. Instead, I'll show how enums and flags help make your code much more readable.
https://wiki.qt.io/API_Design_Principles
0:00 Comparing QSlider API between Qt3 and Qt4
1:52 Qt3: update(false) ← what does that mean?
3:09 Going from booleans to enums
4:45 party(false, false, true) converted to bitwised-or flags
6:38 bitwise flags in the DepecheModel
8:18 The exceptions where it is OK to use booleans
The example code showcased in this video is available here: https://github.com/KDAB/kdabtv/tree/master/Qt-Widgets-and-more/no-more-booleans
All QML tips and tricks videos : https://www.youtube.com/playlist?list=PL6CJYn40gN6jWHP5krsQrVGyYtKh3A3be
All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI
Stay on top of the latest news, publications, events and more.
Go to Sign-up
Upgrade your applications from Qt 5 to Qt 6 with KDAB’s migration services. Get a free migration assessment and join a hands-on workshop to prepare your team for a successful transition!
Learn more