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.
A couple of weeks ago, we guided you through setting up a chat application and server in our first blog of this series. This is the second and final blog of this Qt Allstack series.
Firebase Messaging
Now that we have a functional chat application, it’s time to add real world features, like push notifications. Firebase Cloud Messaging allows you to send push notifications to your users while your app is not running and integrates with APNs (Apple Push Notification services). This way, you only care about one API and can have push notifications on both Android and iOS.
It is important to note here that, even though you can choose not to use Cutelyst on your backend, you still need to add Firebase support on your mobile application. It needs to link to the Firebase library so it can retrieve an unique device token. Once you have the Firebase token, you can send push notifications using any kind of server. Since the idea is to use Qt on all stacks, we will cover how to do so in Cutelyst.
Back in the ChatAppBack project, we need to fetch and link to FirebaseAdminQt. Since Google doesn’t provide a Qt/C++ FirebaseAdminSDK, I have implemented one that supports some of its features.
CMake can fetch, compile and link it for you, to do so open the main CMakeLists.txt and add:
We now need to filter the messages to find out whether we should send a notification to a user. We will add two methods: one to filter the message and query the user's firebase_token and another to send the message to Firebase servers to be pushed to the mobile phone:
voidRoot::sendPushNotifications(const QString &message){ QStringList users; QRegularExpression re("@([a-zA-Z0-9_]{3,})");auto globalMatch = re.globalMatch(message);while(globalMatch.hasNext()){ QRegularExpressionMatch match = globalMatch.next(); users << match.captured(1);} users.removeDuplicates();for(constauto&user :qAsConst(users)){APool::database().exec(u"SELECT data->>'firebase_token' FROM users WHERE nick=$1",{ user,},[=](AResult &result){auto firstRow = result.begin();if(!result.error()){if(result.size()&&!result[0][0].toString().isEmpty()){sendPushNotification(result[0][0].toString(), message);}}else{qWarning()<<"Failed to get firebase_token for user"<< user << result.errorString();}},this);}}voidRoot::sendPushNotification(const QString &deviceToken,const QString &message){ FirebaseMessage msg; msg.setToken(deviceToken); QString title ="ChatApp - New Message"; msg.setNotification(title, message); FirebaseAndroidNotification android; android.setTitle(title); android.setBody(message); msg.setAndroid(android); FirebaseAdminReply *reply = m_fbAdminMsg->send(msg);connect(reply,&FirebaseAdminReply::finished,this,[=]{ reply->deleteLater();if(reply->error()){qDebug()<<"FIREBASE error"<< reply->errorCode()<< reply->errorMessage();}else{qDebug()<<"FIREBASE success"<< reply->messageId();}});}
Then, at the root.cpp file on messages_POST, we add the following line when we've successfully retrieved our message id:
sendPushNotifications(msg);
Finally, we need to initialize Firebase Admin by adding the following code at the postFork() function inside root.cpp:
auto fbApp =newFirebaseAdmin(this); fbApp->setAccountCredentialData(R"V0G0N(
<REPLACE WITH SERVICE ACCOUNT JSON>
)V0G0N"); fbApp->getAccessToken();auto messaging =newFirebaseAdminMessaging(fbApp); messaging->setApiKey("<REPLACE SERVER API KEY>");returntrue;
To fill both fields, we now need to create a Firebase project. So, please open the Firebase console. The FCM documentation can be found here. If you'd like more information on Firebase projects, click here.
On the Firebase website, click on “Create a project” or "Add project" (if you already have one). Give it a name, like ChatApp. In the next step, Google Analytics is not required and for simplicity, disable it. It will then create your new project and take you to the project’s dashboard.
Select "Project Settings" on the Firebase dashboard:
Choose the “Service Accounts” tab. There, we will have Firebase Admin SDK information. Click “Generate new private key.” This will download a JSON file containing the server credentials. You can either add code to read the file or copy its contents and replace the placeholder that we left on root.cpp:
FirebaseAdmin::setAccountCredentialData();
Now we select the “Cloud Messaging” tab. In “Project Credentials”, copy the token of the “Server Key” key, and replace the placeholder that we left on root.cpp:
FirebaseAdminMessaging::setApiKey();
Let’s also create a generic method to send the push notifications on root.cpp:
Let’s switch back to our QML app and prepare ChatApp for Android. We will ask Qt Creator to create the Android templates. To do so, select “Projects” → select “Android Qt 5.15.2” kit → then, in “Build Android APK”, choose “Create Templates”. On the wizard, select to copy the gradle files checkbox, too:
Once the templates are created, you will have the Android manifest open in an editor. I recommend avoiding using that editor, as it usually reformats the XML. For now, just change the “Package Name” to “com.kdab.chatapp”. This is the ID of your APK that will eventually be published in the Google Play Store. We'll need it on the Firebase console.
On the dashboard, there will be an Android icon with the information to “add an app to get started”. It will now show a page to register your app. I’ll put “com.kdab.chatapp” under the Android package name and then click on “Register App”, (a hash will be appended to your project id).
The next step will generate a “google-services.json” that we will need to have on our app. Download it and have it stored inside the android folder we created earlier on the app. Go to ChatApp.pro and add the following line:
DISTFILES += android/google-services.json
We will not cover the step-by-step for getting APNs to work, as that is well-covered on the web. On this Firebase Console page you can also add your iOS app information and it will provide fields for adding the your APNs certificates.
Add the QtAndroidExtras library to the top of the ChatApp.pro file:
This is required so that the C++ Firebase library can initialize and create a new unique token to identify your device, for privacy reasons you are not allowed to obtain any phone identification.
The next step, “Add Firebase SDK”, should be ignored because it doesn’t cover Qt. So click “Continue to Console”.
It's time to finish and integrate Firebase C++ into our code. To start, download the Firebase C++ SDK from here. You will have a ZIP file, which you should extract beside your ChatApp project directory.
Notice that this isn’t the latest version, but rather an older version that works. The latest version has issues calling the Java classes. This version, although old, still works without issues. On iOS we will need this very same ZIP file, but will need to manually download the Firebase iOS SDK. It usually offers adding it with Cocoa PODS, but QMake has no support for it. Basically, on iOS, the C++ SDK will talk to that of the iOS. It took me a long time to figure this out, but at least our C++ code is left untouched.
Firebase C++ SDK has one caveat, though: when a request is made or when a callback method is called, they are not on Qt's main GUI thread. To make integration easier, I created another Qt Wrapper, but the code is not state-of-the-art. So, we must connect to all its signals using Qt::QueuedConnection.
Firebase Qt also has a class for phone authentication, which uses SMS to validate the user’s mobile phone and can easily be extended to support the other authentication methods supported by the Firebase Authentication module, which we won’t cover here.
Still on ChatApp.pro, we will add the required code to be able to work on both 32-bit and 64-bit Android. We can also check the iOS part on the git repository of this project:
#This is the path for the Firebase C++ SDKGOOGLE_FIREBASE_SDK = $$PWD/../firebase_cpp_sdk
#This is the path for the iOS Firebase SDKGOOGLE_IOS_FIREBASE_SDK = $$PWD/../Firebase
INCLUDEPATH += $${GOOGLE_FIREBASE_SDK}/include
DEPENDPATH += $${GOOGLE_FIREBASE_SDK}/include
contains(ANDROID_TARGET_ARCH,armeabi-v7a){ ANDROID_PACKAGE_SOURCE_DIR = \
$$PWD/android
LIBS +=-L$${GOOGLE_FIREBASE_SDK}/libs/android/armeabi-v7a/c++/-lfirebase_app -lfirebase_messaging
PRE_TARGETDEPS += $${GOOGLE_FIREBASE_SDK}/libs/android/armeabi-v7a/c++/libfirebase_app.a
PRE_TARGETDEPS += $${GOOGLE_FIREBASE_SDK}/libs/android/armeabi-v7a/c++/libfirebase_messaging.a
}contains(ANDROID_TARGET_ARCH,arm64-v8a){ ANDROID_PACKAGE_SOURCE_DIR = \
$$PWD/android
LIBS +=-L$${GOOGLE_FIREBASE_SDK}/libs/android/arm64-v8a/c++/-lfirebase_app -lfirebase_messaging
PRE_TARGETDEPS += $${GOOGLE_FIREBASE_SDK}/libs/android/arm64-v8a/c++/libfirebase_app.a
PRE_TARGETDEPS += $${GOOGLE_FIREBASE_SDK}/libs/android/arm64-v8a/c++/libfirebase_messaging.a
}
Here, we link to firebase_app and firebase_messaging. As on iOS, Firebase C++ SDK, when running on Android requires it’s Java libraries, we get them by changing the build.gradle:
We are now able to proceed to using it, creating a Firebase class that will serve us as the QML glue. So, let's ask QtCreator to create a new C++ class called Firebase that inherits from QObject. The new firebase.h will look like:
The two methods will be called by Firebase C++ SDK, the first one when it initializes and the second one when a push notification is received but the application is running. In this case, Android does not show the popup but you still get the data. The token property will be sent to the backend; it's needed to be able to send a notification to this device.
On firebase.cpp:
#include<QLoggingCategory>#include"firebase-qt/src/firebaseqtapp.h"#include"firebase-qt/src/firebaseqtmessaging.h"Firebase::Firebase(QObject *parent):QObject(parent){#ifdefined(Q_OS_ANDROID)||defined(Q_OS_IOS)auto firebase =newFirebaseQtApp(this);auto messaging =newFirebaseQtMessaging(firebase);connect(messaging,&FirebaseQtMessaging::tokenReceived,this,&Firebase::tokenReceived, Qt::QueuedConnection);connect(messaging,&FirebaseQtMessaging::messageReceived,this,&Firebase::messageReceived, Qt::QueuedConnection); firebase->initialize();#endif}voidFirebase::tokenReceived(const QByteArray &token){qDebug()<<"Got Firebase Messaging token"<< token; _token =QString::fromLatin1(token); Q_EMIT tokenChanged();}voidFirebase::messageReceived(const QMap<QString, QString>&data){qDebug()<<"Got a Push Notification when the app is running"<< data;}
As we can see, we need FirebaseQtApp, which is required by all Firebase modules. Then, we connect the signals to our methods using Qt::QueuedConnection. When testing with the USB cable, we will be able to see the debug message when messageReceived is called. But we will ignore its data.
We will now export this class as a QML singleton because we need the token to be sent when the user is created. Add the following to main.cpp before you create the QGuiApplication instance:
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.
Nice article! It is helpful because sometimes we get unnecessary notifications. It will be helpful for people who want to turn on or off the notification in their androids.
20 - Jun - 2024
Vidya Patil
I am trying to add firebase to my qt5 project. I want to use login with google feature and add data to firestore / Realtime db. Can you please provide any pointer for the same?
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.
4 Comments
8 - Nov - 2022
Wonderpush
Nice article! It is helpful because sometimes we get unnecessary notifications. It will be helpful for people who want to turn on or off the notification in their androids.
20 - Jun - 2024
Vidya Patil
I am trying to add firebase to my qt5 project. I want to use login with google feature and add data to firestore / Realtime db. Can you please provide any pointer for the same?
20 - Jun - 2024
Daniel Nicoletti
For auth https://firebase.google.com/docs/reference/cpp/namespace/firebase/auth which has the phone method covered by https://github.com/cutelyst/firebase-qt/blob/master/src/firebaseqtauth.h , for firestore there is https://firebase.google.com/docs/reference/cpp/namespace/firebase/firestore but there is no Qt wrapper around it, so you can either add one or just use their C++ classes directly, you only need to be careful about threading since their std::futures will return on a different thread.
20 - Sept - 2024
Jiri
hello @Daniel, any chance of any update on CMake? I know you working on it, but let us know something please