Trusted Software Excellence across Desktop and Embedded
Take a glance at the areas of expertise where KDAB excels ranging from swift troubleshooting, ongoing consulting and training to multi-year, large-scale software development projects.
Find out why customers from innovative industries rely on our extensive expertise, including Medical, Biotech, Science, Renewable Energy, Transportation, Mobility, Aviation, Automation, Electronics, Agriculture and Defense.
High-quality Embedded Engineering across the Stack
To successfully develop an embedded device that meets your expectations regarding quality, budget and time to market, all parts of the project need to fit perfectly together.
Learn more about KDAB's expertise in embedded software development.
Where the capabilities of modern mobile devices or web browsers fall short, KDAB engineers help you expertly architect and build high-functioning desktop and workstation applications.
Extensible, Safety-compliant Software for the Medical Sector
Create intelligent, patient-focused medical software and devices and stay ahead with technology that adapts to your needs.
KDAB offers you expertise in developing a broad spectrum of clinical and home-healthcare devices, including but not limited to, internal imaging systems, robotic surgery devices, ventilators and non-invasive monitoring systems.
Building digital dashboards and cockpits with fluid animations and gesture-controlled touchscreens is a big challenge.
In over two decades of developing intricate UI solutions for cars, trucks, tractors, scooters, ships, airplanes and more, the KDAB team has gained market leading expertise in this realm.
Build on Advanced Expertise when creating Modern UIs
KDAB assists you in the creation of user-friendly interfaces designed specifically for industrial process control, manufacturing, and fabrication.
Our specialties encompass the custom design and development of HMIs, enabling product accessibility from embedded systems, remote desktops, and mobile devices on the move.
Legacy software is a growing but often ignored problem across all industries. KDAB helps you elevate your aging code base to meet the dynamic needs of the future.
Whether you want to migrate from an old to a modern GUI toolkit, update to a more recent version, or modernize your code base, you can rely on over 25 years of modernization experience.
KDAB offers a wide range of services to address your software needs including consulting, development, workshops and training tailored to your requirements.
Our expertise spans cross-platform desktop, embedded and 3D application development, using the proven technologies for the job.
When working with KDAB, the first-ever Qt consultancy, you benefit from a deep understanding of Qt internals, that allows us to provide effective solutions, irrespective of the depth or scale of your Qt project.
Qt Services include developing applications, building runtimes, mixing native and web technologies, solving performance issues, and porting problems.
KDAB helps create commercial, scientific or industrial desktop applications from scratch, or update its code or framework to benefit from modern features.
Discover clean, efficient solutions that precisely meet your requirements.
Boost your team's programming skills with in-depth, constantly updated, hands-on training courses delivered by active software engineers who love to teach and share their knowledge.
Our courses cover Modern C++, Qt/QML, Rust, 3D programming, Debugging, Profiling and more.
The collective expertise of KDAB's engineering team is at your disposal to help you choose the software stack for your project or master domain-specific challenges.
Our particular focus is on software technologies you use for cross-platform applications or for embedded devices.
Since 1999, KDAB has been the largest independent Qt consultancy worldwide and today is a Qt Platinum partner. Our experts can help you with any aspect of software development with Qt and QML.
KDAB specializes in Modern C++ development, with a focus on desktop applications, GUI, embedded software, and operating systems.
Our experts are industry-recognized contributors and trainers, leveraging C++'s power and relevance across these domains to deliver high-quality software solutions.
KDAB can guide you incorporating Rust into your project, from as overlapping element to your existing C++ codebase to a complete replacement of your legacy code.
Unique Expertise for Desktop and Embedded Platforms
Whether you are using Linux, Windows, MacOS, Android, iOS or real-time OS, KDAB helps you create performance optimized applications on your preferred platform.
If you are planning to create projects with Slint, a lightweight alternative to standard GUI frameworks especially on low-end hardware, you can rely on the expertise of KDAB being one of the earliest adopters and official service partner of Slint.
KDAB has deep expertise in embedded systems, which coupled with Flutter proficiency, allows us to provide comprehensive support throughout the software development lifecycle.
Our engineers are constantly contributing to the Flutter ecosystem, for example by developing flutter-pi, one of the most used embedders.
KDAB invests significant time in exploring new software technologies to maintain its position as software authority. Benefit from this research and incorporate it eventually into your own project.
Start here to browse infos on the KDAB website(s) and take advantage of useful developer resources like blogs, publications and videos about Qt, C++, Rust, 3D technologies like OpenGL and Vulkan, the KDAB developer tools and more.
The KDAB Youtube channel has become a go-to source for developers looking for high-quality tutorial and information material around software development with Qt/QML, C++, Rust and other technologies.
Click to navigate the all KDAB videos directly on this website.
In over 25 years KDAB has served hundreds of customers from various industries, many of them having become long-term customers who value our unique expertise and dedication.
Learn more about KDAB as a company, understand why we are considered a trusted partner by many and explore project examples in which we have proven to be the right supplier.
The KDAB Group is a globally recognized provider for software consulting, development and training, specializing in embedded devices and complex cross-platform desktop applications.
Read more about the history, the values, the team and the founder of the company.
When working with KDAB you can expect quality software and the desired business outcomes thanks to decades of experience gathered in hundreds of projects of different sizes in various industries.
Have a look at selected examples where KDAB has helped customers to succeed with their projects.
KDAB is committed to developing high-quality and high-performance software, and helping other developers deliver to the same high standards.
We create software with pride to improve your engineering and your business, making your products more resilient and maintainable with better performance.
KDAB has been the first certified Qt consulting and software development company in the world, and continues to deliver quality processes that meet or exceed the highest expectations.
In KDAB we value practical software development experience and skills higher than academic degrees. We strive to ensure equal treatment of all our employees regardless of age, ethnicity, gender, sexual orientation, nationality.
Interested? Read more about working at KDAB and how to apply for a job in software engineering or business administration.
The familiar solution for thick value classes that want to preserve binary compatibility is to use the pimpl pattern (private implementation), also known as d-pointer (pointer to data). In future versions of our class, we can freely change the contents of the pimpl (i.e. adding, removing, and/or modifying data members) but the binary compatibility of the public class gets preserved.
There's a minor variation of the pimpl pattern that can enable some performance improvements by not allocating the private data in all cases. The idea is pretty simple: move (some of) the data members in the public class, while still keeping a d-pointer data member.
This optimization makes a lot of sense, if the class that we're pimpling does not hold a lot of state. In general, there are multiple reasons why one may want to conditionally allocate the private data:
maybe we don't need it at all at the moment (again, class with a small state). We want to have room for it "just in case" we need to "grow" our class sometime in the future and want to keep binary compatibility (so we can't just add new data members to it) and/or
because the pimpl stores data that it's only seldom needed. In the "common case," we can spare the allocation for that data.
The second scenario isn't really interesting; it's a normal lazy allocation.
Let's, instead, assume we're in scenario number 1, in which the d-pointer is unused right now but there as room for future growth. Let's further assume that we are not also using implicit sharing or any other complications of that nature.
In this scenario, a pimpled class will look something like this:
classWiperSettings{public:enumclassStatus:int8_t{ Off, Slow, Medium, Fast }; EXPORT WiperSettings(); EXPORT ~WiperSettings(); EXPORT WiperSettings::WiperSettings(const WiperSettings &); EXPORT WiperSettings &operator=(const WiperSettings &);inlineWiperSettings(WiperSettings &&)noexcept;inline WiperSettings &operator=(WiperSettings &&)noexcept;inlinevoidswap(WiperSettings &)noexcept); EXPORT Status getStatus()const; EXPORT voidsetStatus(Status);private: Status s;// current inline state, smallclassWiperSettingsPrivate*d;// dpointer for future expansion};
In the above snippet, I am highlighting which members are exported and out of line and which ones are inline. We must be extra careful with inline functions, as, generally speaking, their code will get compiled into the calling code. The consequence of this is that we can't change their semantics while keeping binary compatibility.
Let's now compare the implementation of thespecial member functions in the current version of the class ("right now") with the implementation "in the future," when the class will need to make use of the d-pointer because it needs to grow.
SMF
Right now (no dpointer used)
In the future (use dpointer)
Remarks
Default ctor
Initialize the status; initialize the d-pointer to nullptr. Although the d-pointer is unused at this moment, we’re going to default other SMFs and we don’t want UB to be triggered by reading uninitialized data.
Initialize the status and allocate the pimpl.
In the future, it will need to change behavior and have access to the complete private class; so, it must be exported and out of line.
Dtor
Default implementation (destroy the members).
Destroy the members and deallocate the pimpl.
Same as above.
Copy ctor
Default implementation (member-wise copies).
Allocate a new pimpl by copying from the existing one.
Same as above.
Copy assignment
Default implementation (member-wise assignments).
Copy and swap, or a more ad-hoc strategy.
While copy and swap is universal and could potentially be inlined, it’s not necessarily the most efficient implementation. If the class is extended, one may need to switch away from copy and swap to a much more efficient strategy. The allocation cost in the copy is going to dwarf the cost of the out of line call anyway.
Move ctor
Move status and d from the source and reset other.d to nullptr, even if we’re not using the d-pointer right now (⚠️). See below.
←←← Has to be the same — it’s inline!
The move constructor can and should be fully inline. Making it out of line introduces overhead for no good reason.
Move assignment
Move and swap.
←←← Has to be the same — it’s inline!
Fully inline as well. Could be implemented in terms of pure swap, but in Qt we prefer the determinism of move and swap when we cannot be sure that a class only holds memory (see here).
Swap
Swap status and swap d, even if we’re not using the d-pointer right now.
←←← Has to be the same — it’s inline!
Fully inline as well.
There is one very important thing to stress in the above table: "right now" the inline move constructor must move the d-pointer over and resetother.d tonullptr, even if we're not using them at all. In other words, the post-condition of the inline move constructor must be this->d is the old value of other.d and other.d is nullptr. This means that the move constructor cannot be defaulted, even if "right now" defaulting it would do the correct thing.
But why is this? The explaination is a bit tricky, so stay with me.
This postcondition is necessary in order to allow thefutureversion of the class to correctly handle destruction/assignment of moved-from instances while keeping the BC promise.
The point is that a move operation that happens in code compiled against the today version of the class will correctly handle an object produced by the future version of the class (remember, in the future the d-pointer is actually being used). Since the move operation is fully inline, it does not get recompiled when we upgrade to the future version of the class. So we must already prepare todayfor an ownership transfer of the d-pointer!
We're at now, now.
To watch this video on our website please or view it directly on YouTube
So far, so good.
There's a further optimization possible. In the current design, each instance has to pay for the storage space of a d-pointer even if it's not using it all. Is it OK to have a class that consumes more space (in the example above it could be twice the size of a pointer, due to padding), just for the sake of binary compatibility? What if this is a super-popular class and you may realistically create thousands or millions of such objects? Are you even sure you're going to use the d-pointer "in the future"?
We can trade size for a small refactoring: "in the future," should we decide to pimpl the class, we'll then fold inside the pimpl the contents of the state currently stored directly in the public class itself. This refactoring lets us change the implementation from a record type (store both inline state and d-pointer) to an alternative type (store either inline state or the d-pointer).
In C++, the alternative type is, of course, std::variant<InlineState, Private *>. Here, it would be the easiest choice but not the ideal type to use, as it would waste space for the index of the current active alternative, where we "statically" know which alternative is active: "right now" it's the inline state, "in the future" the pimpl.
So, a union it is, and no extra space required:
classWiperSettings{public:~~~private:union{// anonymous Status s; WiperSettingsPrivate *d;};};
Let's do the exercise again. What do we do in each special member function now?
SMF
Right now (no dpointer used)
In the future (use dpointer)
Default ctor
Initialize s.
Initialize d by allocating the pimpl.
Dtor
Default implementation (destroy the members).
Deallocate d.
Copy ctor
Default implementation (member-wise copies).
Allocate a new pimpl by copying from the existing one.
Copy assignment
Default implementation (member-wise assignments).
Copy and swap, or a more ad-hoc strategy.
Move ctor
⚠️⚠️⚠️
←←← Has to be the same, it’s inline!
Move assignment
Move and swap.
←←← Has to be the same, it’s inline!
Swap
⚠️⚠️⚠️
←←← Has to be the same, it’s inline!
Now we have a problem: we can no longer meaningfully implement an inline move constructor and we cannot implement swap. (And therefore we can't implement move and swap -- that uses both). Why is that?
Remember: the move constructor must carry the d-pointer from the source object (other) onto *this and reset other.d to nullptr, if we want to preserve binary compatibility. (other may come from "the future." The move constructor is inlined "right now").
With this necessary post-condition, the straightforward implementation doesn't work:
This move constructor is reading from other.d "right now", but that union field is not active! That's completely illegal in C++ (file under "UB that works in pratice").
The same problem applies to an inline swap -- which member of the union do we swap? Right now we're supposed to swap s, but that makes it binary incompatible with an object from the future, where d is in use.
A workaround here is possible, but only if the inline state is trivial (so an enum is fine, an int is fine, a struct containing enum+int is fine; but a QString is not fine). The workaround simply consists of making the union not anonymous and moving/swapping the entire union.
classWiperSettings{public:~~~private:union U { Status s; WiperSettingsPrivate *d;} u;};
The move constructor and swap function then become:
The trick here is that, by moving/swapping the union (as opposed as a union's member), we make C++ responsible for making correct that the active field is the one actually moved. It's no longer our problem!
This is also the reason for imposing triviality for the inline state; otherwise, the union's special member functions are not necessarily generated (whoops!) and we cannot switch the active member of the union (in the move constructor, we enable other.u.d) without first of calling an explicit destructor on the currently active union member; and we don't know which one is enabled.
You'll find this pattern soon deployed in a Qt version near you, for instance, in the new QPermission datatypes. Many thanks toMarc Mutz for implementing the above design in many commits to Qt (e.g.here,here).
About KDAB
Trusted software excellence across embedded and desktop platforms
The KDAB Group is a globally recognized provider for software consulting, development and training, specializing in embedded devices and complex cross-platform desktop applications. In addition to being leading experts in Qt, C++ and 3D technologies for over two decades, KDAB provides deep expertise across the stack, including Linux, Rust and modern UI frameworks. With 100+ employees from 20 countries and offices in Sweden, Germany, USA, France and UK, we serve clients around the world.
have you a simple test on github ?I should test/study this pattern.
Thanks
29 - Jun - 2023
Giuseppe D'Angelo
I don't, but this has been implemented in Qt, just follow the last couple links in the blog / check out the qpermission classes from qtbase.
Giuseppe D’Angelo
Senior Software Engineer
Senior Software Engineer at KDAB. Giuseppe is a long-time contributor to Qt, having used Qt and C++ since 2000, and is an Approver in the Qt Project. His contributions in Qt range from containers and regular expressions to GUI, Widgets, and OpenGL. A free software passionate and UNIX specialist, before joining KDAB, he organized conferences on opensource around Italy. He holds a BSc in Computer Science.
Our hands-on Modern C++ training courses are designed to quickly familiarize newcomers with the language. They also update professional C++ developers on the latest changes in the language and standard library introduced in recent C++ editions.
2 Comments
29 - Jun - 2023
Piegiorgio
Hi Giuseppe,
have you a simple test on github ?I should test/study this pattern.
Thanks
29 - Jun - 2023
Giuseppe D'Angelo
I don't, but this has been implemented in Qt, just follow the last couple links in the blog / check out the qpermission classes from qtbase.