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.
In the last blog post we gave a very high level introduction to the Qt Quick 2 renderer. We also showed how various signals are emitted by the renderer during the synchronization and rendering steps. In this blog post we're going to discuss those signals and show how they can be used to implement overlays and underlays.
Signals emitted by the Qt Quick renderer
Let's start again by looking at this diagram of the synchronization between the render thread of the renderer and the main thread when a new frame needs to be rendered:
What are exactly the signals emitted by the Qt Quick 2 renderer that we can use? Some of them are visible in the picture above, some of them are not, so I will list all of them here:
QQuickWindow::sceneGraphInitialized: emitted when the renderer initializes the OpenGL context and the scene graph resources.
QQuickWindow::sceneGraphInvalidated: emitted when the renderer has invalidated the scene graph, and the OpenGL resources should be freed.
QQuickWindow::beforeSynchronizing: emitted before the scene graph synchronizes with the main thread. However, the main thread is already blocked at this point.
QQuickWindow::afterSynchronizing: emitted after the scene graph synchronized with the main thread. The main thread is still blocked at this point.
QQuickWindow::beforeRendering: emitted before any rendering by the Qt Quick renderer has taken place.
QQuickWindow::afterRendering: emitted after the Qt Quick renderer has rendered the scene graph.
QQuickWindow::frameSwapped: emitted after the Qt Quick renderer has swapped the back and the front buffers.
That is a lot of signals indeed! But it's extremely good news, because it means we can intervene at any point of the synchronization/render process by simply connecting slots to these signals. An important consideration is that the OpenGL context used by the Qt Quick renderer will be bound when the signals are emitted. This means we can simply have OpenGL calls in our slots, without the problem of finding the "right" OpenGL context to use and make it current.
Also, note that the signals are emitted from the render thread, not the main thread. This typically means that we will need to force the connection type to Qt::DirectConnection, if the receiver object lives in the main thread. It also means we will need to carefully manage shared state between the main thread and the GUI thread, for instance by protecting the state with mutexes.
Remember that after the synchronization is complete, the main thread is unblocked and free to go while the rendering signals are being emitted; we can easily have races between the main thread and slots invoked directly from the render thread.
OpenGL underlays and overlays
So how can we implement, for instance, a simple underlay (that is, drawing custom OpenGL content below a scene)? Here's a screenshot of an example application:
The trefoil knot is rendered by an external piece of OpenGL code that we are not going to discuss here. Let's assume is some existing code we don't want to touch, and treat it as a black box. The small controls on the bottom are instead implemented using Qt Quick. As you can see, the controls are truly over the OpenGL content, and nicely blended with it.
The three sliders control the position of the virtual camera in the world (in spherical coordinates). For simplicity, these coordinates are wrapped by a Camera class, an instance of which gets exposed to the QML engine.
How can we obtain this result using the signals emitted by Qt Quick? Here you are the relevant parts of a possible implementation, done using a subclass of QQuickView.
In the constructor a Camera object gets created, representing the position of our virtual camera, and a MeshRenderer object, which is our black box performing OpenGL rendering (drawing the knot).
We then connect some of the signals emitted by the Qt Quick renderer to some local slots. We're not interested in all of them; for this example just want to know:
when the scene graph is getting created and destroyed, so we can initialize and release the OpenGL resources;
when the synchronization round is happening, so we can safely access state in the main thread (which is blocked);
when Qt Quick is about to start rendering the next frame, so we can paint before it, therefore realizing an underlay.
Notice the Qt::DirectConnection connection type. Since the receiver (this) is living in the main thread, and the signal is emitted by the render thread, we must force the connection type otherwise it would result in a queued invocation, with disastrous results.
After those connections, we connect the update slot to the various changed signals from the Camera object, because every time the camera moves we want to schedule a redraw.
We then ask Qt Quick not to issue a glClear on the color buffer before starting its own rendering. Since we want to draw something before Qt Quick, clearing would result in not seeing anything of what we had rendered. The setClearBeforeRendering call disables (or enables) the automatic clearing.
Finally, we expose the Camera object to QML (so that it can be manipulated through the Qt Quick sliders) and load a QML file.
What about the slots themselves? Let's have a look:
Yes, it's that simple! Since our renderer is a black box, we simply call into it from the slots.
When the scene graph is initialized or invalidated, we respectively initialize or invalidate our renderer.
When Qt Quick is about to render itself, we call our own rendering code, resulting in drawing below Qt Quick.
A bit more interesting is the synchronization slot. Remember that all these slots are called directly from the render thread; as such, concurrent access from the main thread could easily result in a data race. While we could expose the Camera object to our custom OpenGL code, we would then need to implement a thread-safe Camera, which may be tricky or just impossible.
For this reason, we've decided to follow what the Qt Quick renderer does: we extract from the objects living in the main thread all the information required for rendering the frame. In this case, the object living in the main thread is m_camera, and the information are the spherical coordinates, which get stored somewhere else (for instance inside our black box renderer). All of this happens during the synchronization stage, while the main thread is blocked, so there is no risk of concurrent access and therefore data races.
Finally, what is the deal with all the resetOpenGLState calls? The fact is that the Qt Quick renderer does not like modifications to the OpenGL state. In other words, if in our slots we modify some OpenGL state (bind textures, change the used shader program, and so on), we must reset the OpenGL state to whatever it was before we touched it.
While this is possible in theory (OpenGL has all the necessary APIs for querying state), it's also terribly complicated due to the countless settings that OpenGL has; moreover, if we simply call into some third party code, we have no control over which state gets touched by that. For this reason, there is a convenience call that resets the OpenGL state: QQuickWindow::resetOpenGLState. Be sure to call this function every time some OpenGL state gets modified in a slot!
That's it!
Further steps
In the next blog post we are going to deeply integrate a custom OpenGL item inside a Qt Quick 2 scene. Stay tuned!
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.
Very nice tutorial. I am evaluating this approach for simplifying the development of a desktop application with a good base of pre-existent OpenGL code for visualizing some custom data structures. The only big question marks I have at the moment are:
(1) Data managment. Assuming that the application many custom 3D data structures to be processed and visualized, where should I store the data? How should I manage updating (or exporting) data to the renderer. In the demo everything is loaded directly by the renderer;
(2) Mouse and keyboard input. Am I able to send quick and precise mouse events to the renderer to implement, for example, a very custom mouse-keyboard interaction with the 3D models. How would I implement such a thing? How it will perform?
Thank you again!
Marco
9 - Feb - 2016
Giuseppe D'Angelo
Hi Marco,
Regarding (1) there are many possible approaches, depending on the nature of your renderer. For instance, you could have your renderer created and destroyed on demand following the corresponding sceneGraph* signals emitted by QQuickWindow. The data structures in theory should follow the renderer, as when the scene graph context gets destroyed, you will lose your OpenGL objects (buffers, textures, etc.), so they would need to be created again. Now, again, you may want to create "frontend" elements to be manipulated in the GUI thread, and corresponding "backend" elements to be manipulated in the render thread, mimicking what Qt Quick does -- so that the renderer has the low-level stuff to just render, while the high level objects stay and live in the main thread. It's really up to you.
(Note that if this multithreading becomes a complication, a quick'n'dirty workaround is disable it (by exporting QSG_RENDER_LOOP and setting it to basic) -- this basically forces Qt Quick to run single threaded.)
In some scenarios you may want more control over the OpenGL context creation, threading, and exactly about when rendering should happen. For those scenarios, stay tuned -- that's the subject of the next instalments of these series, involving QQuickRenderControl.
Regarding (2) there should be no problems at all, just subclass QQuickWindow or QQuickView and override the event handlers -- or, catch mouse/keyboard events inside the Qt Quick scene and handle them appropriately.
For an underlay you can use an approach like:
class MyQuickView : public QQuickView
{
protected:
void mousePressEvent(QMouseEvent *e) override {
QQuickView::mousePressEvent(e); // let Qt Quick handle it first...
if (!e->isAccepted()) // the click didn't land on anything in Qt Quick, I'll use it then
doMyHandling(e);
}
};
Hope this helps,
7 - Jun - 2017
milad hasanvand
hi
thank you for your comprehensive explanations.
I having a rather unsolvable problem with scenegraph. my renderer class needs to query a database to draw the scene. how should I solve this?
I tried singleton type - it didn't work because the qml object is not creatable
should I read the database in another object and pass it to the renderer through QML?
11 - Jun - 2017
Giuseppe D'Angelo
Hello,
In general this should be perfectly possible. You can query the database during the synchronization step, then give data to render to the renderer during the begin/after rendering phase.
16 - Dec - 2019
Huchn
Hello,
Where is the next blog post?
7 - Apr - 2020
Reza
Hello Giuseppe
Thanks for the post
It's so usefull
I don't know can get any reply here or not, but I'll ask my question
The question is related to events on these methods you explained one of them here
I checked the source code and tried to add mousePressEvent on them,
in Underlay method, it made the controllers freezed and it was not possible to interact with 3d object(even printing something)
in related to RenderControll method, mousePressEvent worked fine, but have different question about it
If we want to put the Window inside an Item of QML, we should create a QQuickItem, then register it as an item and use the RenderWindow in it? (I mean it should be connect to SIGNALS like sync and beforeRendering, .. or not?) this is a little bit ambiguous for me
please reply
thanks again
21 - May - 2020
Giuseppe D'Angelo
Hi,
Unfortunately it's a bit hard to understand what went wrong. You should be able to subclass QQuickWindow and override the mouse event handlers (although it could be a bit "crude" in terms of a solution, but depends on your needs). Regarding 2, are you talking about adding a GL-drawn QQuickWindow inside a Qt Quick scene?
5 - May - 2020
Tomasso
Excellent post, Guiseppe.
Can I use this overlay/underlay approach when I want the QML to display menu bars, as ApplicationWindow does? QQuickView doesn't seem to directly support menu bars.
Thanks!
Tom
21 - May - 2020
Giuseppe D'Angelo
Hi,
You might go for that approach, but it sounds quite complicated (it would require to draw the menu using pure OpenGL, and handle mouse events, etc.). Isn't a solution using Qt Quick itself not suitable for you? (E.g. by using Qt Quick Controls 2)
21 - May - 2020
Dusan
So where is the promised next post? I promise I won't steal your clients, I'm just curious how to integrated custom GL renderers with Qt Quick. Thank you for this blog post tho, very nice of you.
I trying to develop a Qt Quick application that shows the live feed from a camera connected to the device and does some overlay graphics like adding points and drawing lines. Which is the best approach to use?
23 - Oct - 2020
Giuseppe D'Angelo
Hello,
It really depends on your needs. You might get away with simply using Qt Quick APIs: use some element for showing the video feed, then overlay it with Image/Qt Quick Shapes/custom QQPaintedItem etc. elements for the annotations.
1 - Dec - 2023
Jeff
very good tutorials and learned a lot!
my problem is when call QQuickWindow::update it will force to update all items in the window which is too heavy for performance, what is want to update just a image that is feed texture by my own image provider, not update all items, but i cannot find elegant method to do it, call item->update() is useless since its texture is render in background. any good suggestion?
5 - Dec - 2023
Giuseppe D'Angelo
Hello Jeff,
How are you updating your texture and how? There's "many ways" to achieve an update. If you're using an image provider, you could just trigger an Image element to reload it (e.g. by altering the URL).
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.
15 Comments
6 - Feb - 2016
Marco Centin
Very nice tutorial. I am evaluating this approach for simplifying the development of a desktop application with a good base of pre-existent OpenGL code for visualizing some custom data structures. The only big question marks I have at the moment are:
(1) Data managment. Assuming that the application many custom 3D data structures to be processed and visualized, where should I store the data? How should I manage updating (or exporting) data to the renderer. In the demo everything is loaded directly by the renderer;
(2) Mouse and keyboard input. Am I able to send quick and precise mouse events to the renderer to implement, for example, a very custom mouse-keyboard interaction with the 3D models. How would I implement such a thing? How it will perform?
Thank you again! Marco
9 - Feb - 2016
Giuseppe D'Angelo
Hi Marco,
Regarding (1) there are many possible approaches, depending on the nature of your renderer. For instance, you could have your renderer created and destroyed on demand following the corresponding
sceneGraph*
signals emitted by QQuickWindow. The data structures in theory should follow the renderer, as when the scene graph context gets destroyed, you will lose your OpenGL objects (buffers, textures, etc.), so they would need to be created again. Now, again, you may want to create "frontend" elements to be manipulated in the GUI thread, and corresponding "backend" elements to be manipulated in the render thread, mimicking what Qt Quick does -- so that the renderer has the low-level stuff to just render, while the high level objects stay and live in the main thread. It's really up to you.(Note that if this multithreading becomes a complication, a quick'n'dirty workaround is disable it (by exporting
QSG_RENDER_LOOP
and setting it tobasic
) -- this basically forces Qt Quick to run single threaded.)In some scenarios you may want more control over the OpenGL context creation, threading, and exactly about when rendering should happen. For those scenarios, stay tuned -- that's the subject of the next instalments of these series, involving QQuickRenderControl.
Regarding (2) there should be no problems at all, just subclass QQuickWindow or QQuickView and override the event handlers -- or, catch mouse/keyboard events inside the Qt Quick scene and handle them appropriately.
For an underlay you can use an approach like:
Hope this helps,
7 - Jun - 2017
milad hasanvand
hi thank you for your comprehensive explanations. I having a rather unsolvable problem with scenegraph. my renderer class needs to query a database to draw the scene. how should I solve this? I tried singleton type - it didn't work because the qml object is not creatable should I read the database in another object and pass it to the renderer through QML?
11 - Jun - 2017
Giuseppe D'Angelo
Hello, In general this should be perfectly possible. You can query the database during the synchronization step, then give data to render to the renderer during the begin/after rendering phase.
16 - Dec - 2019
Huchn
Hello, Where is the next blog post?
7 - Apr - 2020
Reza
Hello Giuseppe Thanks for the post It's so usefull I don't know can get any reply here or not, but I'll ask my question
The question is related to events on these methods you explained one of them here I checked the source code and tried to add mousePressEvent on them, in Underlay method, it made the controllers freezed and it was not possible to interact with 3d object(even printing something)
in related to RenderControll method, mousePressEvent worked fine, but have different question about it If we want to put the Window inside an Item of QML, we should create a QQuickItem, then register it as an item and use the RenderWindow in it? (I mean it should be connect to SIGNALS like sync and beforeRendering, .. or not?) this is a little bit ambiguous for me
please reply thanks again
21 - May - 2020
Giuseppe D'Angelo
Hi, Unfortunately it's a bit hard to understand what went wrong. You should be able to subclass QQuickWindow and override the mouse event handlers (although it could be a bit "crude" in terms of a solution, but depends on your needs). Regarding 2, are you talking about adding a GL-drawn QQuickWindow inside a Qt Quick scene?
5 - May - 2020
Tomasso
Excellent post, Guiseppe. Can I use this overlay/underlay approach when I want the QML to display menu bars, as ApplicationWindow does? QQuickView doesn't seem to directly support menu bars.
Thanks! Tom
21 - May - 2020
Giuseppe D'Angelo
Hi, You might go for that approach, but it sounds quite complicated (it would require to draw the menu using pure OpenGL, and handle mouse events, etc.). Isn't a solution using Qt Quick itself not suitable for you? (E.g. by using Qt Quick Controls 2)
21 - May - 2020
Dusan
So where is the promised next post? I promise I won't steal your clients, I'm just curious how to integrated custom GL renderers with Qt Quick. Thank you for this blog post tho, very nice of you.
21 - May - 2020
Giuseppe D'Angelo
Hi, I had been busy elsewhere and didn't get the time to write a proper 3rd instalment to this series... I have anyhow discussed these solutions in some conference talks, for instance here https://www.kdab.com/development-resources/kdab-qt-world-summit-2017/
Hope this helps!
21 - Oct - 2020
Aditya
Great Post, Mr.Giuseppe,
I trying to develop a Qt Quick application that shows the live feed from a camera connected to the device and does some overlay graphics like adding points and drawing lines. Which is the best approach to use?
23 - Oct - 2020
Giuseppe D'Angelo
Hello,
It really depends on your needs. You might get away with simply using Qt Quick APIs: use some element for showing the video feed, then overlay it with Image/Qt Quick Shapes/custom QQPaintedItem etc. elements for the annotations.
1 - Dec - 2023
Jeff
very good tutorials and learned a lot! my problem is when call QQuickWindow::update it will force to update all items in the window which is too heavy for performance, what is want to update just a image that is feed texture by my own image provider, not update all items, but i cannot find elegant method to do it, call item->update() is useless since its texture is render in background. any good suggestion?
5 - Dec - 2023
Giuseppe D'Angelo
Hello Jeff, How are you updating your texture and how? There's "many ways" to achieve an update. If you're using an image provider, you could just trigger an Image element to reload it (e.g. by altering the URL).