https://www.kdab.com/cxx-qt/ Skip to content x How can we help you? Thanks for your interest in KDAB. Please write your message here and we'll get back to you as soon as possible. Name: * [ ] E-Mail: * [ ] Company: [ ] Phone: [ ] [ ] [ ] [ ] [ ] Message: * [ ] KDAB is committed to ensuring that your privacy is protected. * Only the above data is collected about you when you fill out this form. * The data will be stored securely. * The data will only be used to contact you about possible business together. * If we do not engage in business within 3 years, your personal data will be erased from our systems. * If you wish for us to erase it earlier, email us at info@kdab.com For more information about our Privacy Policy, please read https://www.kdab.com/about/kdab-privacy-policy/ [ ]* I have read and agree to the terms above. [ ] Yes, sign me up for the KDAB newsletter [Send] x Contact us Germany - KDAB (Deutschland) GmbH Reuchlinstrasse 10-11, 10553 Berlin +49 30 5213 254 70 +49 30 5213 254 99 info-de@kdab.com Other countries US: +1.866.777.5322 SE: +46 563 540090 FR: +33 4 90 84 08 53 UK: +44 1625 809908 Full list of all countries x Contact us Name[ ] E-Mail[ ] Company[ ] E-Mail[ ] [ ] [ ] [ ] Message[ ] Please attach your CV (PDF only) [ ] captcha [ ] [Send request] [ ] [ ] [ ] [ ] [ ] [ ] [ ] D[ ] * Services + Projects o Code Migration o Modernization o Development o Consulting & Architecture o Mentoring & Support + Workshops o Code Migration & Modernization o Architecture o Profiling & Performance o Testing & Refactoring o Agile Development + Design Services + Training: On-Site o Qt Training # Qt Widgets for the Desktop # Qt/QML Training # Qt/QML for Embedded Training # Advanced QML Training # Advanced Qt Widgets Training o C++ Training # Modern C++: Introduction # Modern C++: C++11 / C++14 / C++17 o Modern OpenGL # Modern OpenGL: Introduction # Modern OpenGL: Advanced Rendering and Effects # Modern OpenGL: Advanced Pipeline and Performance o Qt 3D Training o Debugging and Profiling # Debugging and Profiling Qt apps on Windows # Debugging and Profiling Qt apps on Linux # Debugging and Profiling C++ apps on Windows # Debugging and Profiling C++ apps on Linux o Other On-site Courses # In-Depth Multithreading # Introduction to CMake # Git Training # Qt with Squish Training # Qt 3D Studio training o Training Facilities o KDAB Trainers o Testimonials o Terms/Conditions + Training: Scheduled o Qt Training # Qt Widgets for the Desktop # Qt/QML Training # QML for Embedded Training # Advanced QML Training # Advanced Qt Widgets Training # Model/View o Modern C++ # Modern C++: C++11 / C++14 / C++17 # Modern C++: Introduction o Modern OpenGL # Modern OpenGL: Introduction # Modern OpenGL: Advanced Rendering & Effects # Modern OpenGL: Advanced Pipeline & Performance o Qt 3D Training o Debugging and Profiling Courses # Debugging and Profiling Qt apps on Windows # Debugging and Profiling Qt apps on Linux # Debugging and Profiling C++ apps on Windows # Debugging and Profiling C++ apps on Linux o In-Depth Multithreading o Introduction to CMake o Testing Qt with Squish o Qt 3D Studio training o Training Schedule o Training Facilities o KDAB Trainers o Testimonials o Terms/Conditions * Expertise + Qt / QML o Qt 3D o Qt on Android o Qt on QNX Neutrino RTOS o Qt on Windows Embedded CE o Qt Tools o Is Qt Right for Your Project? + C++ o C++ Latest Standards o C++ Tools o C++ Training # Modern C++: Introduction # Modern C++: C++11 / C++14 / C++17 + 3D / OpenGL o OpenGL o KUESA 3D Studio o KUESA glTF Library o Qt 3D o Vulkan * Platforms + Android + Linux + Web integration + QNX + Windows Embedded + Mobile iOS/Android + Windows + macOS + Unix / X11 (Motif) * Resources + Blogs + KDAB TV o News o Academy # Introduction to Qt/QML # Qt Widgets and more... # Kuesa 3D # GammaRay # Presentations o Showcases o Events # Demos o Archive + Monthly Newsletter Digest + Content Library Search + Whitepapers, Brochures & Articles + Success Stories + Conferences o Qt Embedded Days o Qt Desktop Days o Qt World Summit # Qt World Summit '20 # Qt World Summit '19 # Qt World Summit '18 # Qt World Summit '17 # Qt World Summit '16 # Qt World Summit '15 o QtCon 2016 o Qt Developer Days # Qt Developer Days 2014 # Qt Developer Days 2013 # Qt Developer Days 2012 + Newsletter + Events + Qt Tools + Qt and CMake resources + Qt Creator Card * [ ] * * * About us + Contact + Customers & Industries + ISO 9001 Certified + Partners + Mission + Working at KDAB + KDAB France + KDAB Japan + Terms and Conditions + Privacy Policy & Cookies Qt/QML C++ 3D/OpenGL Qt/QML C++ 3D/OpenGL CXX-Qt Safe Rust Bindings for Qt # 02.03.2022 # Andrew Hayzen # No comments FacebookTwitterLinkedInEmail At KDAB, we have been investigating how to integrate Rust with Qt in a safe and idiomatic way. The solution we are currently working on is called CXX-Qt. It's available in the GitHub and on crates.io. This blog post discusses the journey of CXX-Qt -- where it started, where it can be used right now, and the future direction of the project. If you would like to get started with code examples, visit our Rust book . Why Rust? Over the past few years, Rust has been gaining popularity in various sectors, from embedded devices to scalable web services. It brings the promise of performance, reliability, and productivity to every sector into which it has been introduced. In addition, Rust is useful from a security perspective due to its memory safety. For instance, a substantial amount of security issues in large-scale C or C++ projects tends to be memory-related. By using Rust, we reduce these kinds of issues while maintaining a level of performance that is on-par with other native languages, like C or C++, and far faster compared to most other memory-safe languages. Where Would Rust Be Useful with Qt? Typical Qt QML applications are composed of multiple parts: * C++ plugins that provide models and represent the business logic * QML, which defines the layout and components of the GUI * JavaScript, for scripting in QML Rust has a rich ecosystem of libraries for (de)serialization, async futures, parsing unsafe inputs, threading, etc. The ability to integrate these Rust libraries into your Qt application makes a compelling story. Therefore, enhancing your C++ plugins and business logic is the most suitable use case for Rust. Due to QML's fast iteration speed and flexibility, we recommend sticking with it for the layout and components of the GUI. Rust Qt Existing Solutions There are many techniques for combining Rust with Qt, each utilizing different ways to bind between Rust and Qt. We found that most solutions tend to have one or more of these problems: * Direct bindings that are not idiomatic to Rust and only provide direct access to the C++ API * Calls between C++ and Rust that are unsafe * They don't make use of Rust's strong multi-threading guarantees or features * They don't have a license that suits the Rust ecosystem * The attempt to use Rust for the whole application rather than just a plugin * No code generation; developers need to manually define the bindings Rust Qt Our Solution Rather than simply providing bindings for the existing C++ API, CXX-Qt makes use of Qt's strong object orientation and meta object system. The library allows you to define new QObject subclasses in Rust as a module. These can then be instantiated like any other QObject in QML, or even C++, if needed. Every QObject defined by CXX-Qt is made up of two parts: * A C++-based QObject instance that stores and exposes properties and invokable methods * A Rust struct that implements any invokables, manages internal state, and handles change requests from properties or background threads CXX-Qt then uses a library called CXX to communicate between Rust and C++. CXX is also being explored by large companies, such as Google, with autocxx. In comparison to normal bindings, CXX creates a bridge between Rust and C++ that is based on a safe subset of the two languages. By using procedural macros, we hide the details of the CXX bridge from you as a developer. We also provide a library of common Qt types that can cross the C++ <-> Rust bridge safely. We furthermore provide mechanisms for Rust background threads to notify and safely update the Qt state on the Qt thread. All of this results in very idiomatic and safe Rust code that can seamlessly interact with existing Qt/C++ and Rust code. The disadvantage of this approach is that we do not provide one-to-one bindings. Therefore, CXX-Qt needs to expose and implement every feature across the bridge. However, as the main focus of our solution is moving a C++ module to Rust, we believe that, for a majority of cases, we will be providing either a QObject or a model to QML and then exposing properties, invokables, and signals on these objects. Rust Qt Current State and Future Direction CXX-Qt is not production-ready or stable and is still a work-in-progress. We welcome any feedback on the direction of the project and features and/or any suggestions you may have. Currently, the existing code is able to perform the following tasks: * Define properties and invokables, exposing them onto a QObject * Use common Qt types * Listen for property changes or handle update requests from background Rust threads In the future, we plan to add the following tasks/features: * Other Qt base classes (such as QAbstractItemModel) * Stabilize the API of macros and improve the API of Qt types * Define and emit signals * Expand the documentation to include tutorials and examples If you would like to contribute, the code is available at https:// github.com/KDAB/cxx-qt and documentation can be found at https:// kdab.github.io/cxx-qt/book. Please feel free to share any suggestions or questions in the blog comments or, if you prefer, send us an email at info@kdab.com. About KDAB If you like this article and want to read similar material, consider subscribing via our RSS feed. Subscribe to KDAB TV for similar informative short video content. KDAB provides market leading software consulting and development services and training in Qt, C++ and 3D/OpenGL. Contact us. FacebookTwitterLinkedInEmail Categories: C++ / KDAB Blogs / KDAB on Qt / QML / Qt / QtDevelopment / Rust / Technical Tags: QML / Qt / Rust Leave a Reply Cancel reply Your email address will not be published. Required fields are marked * [ ] [ ] [ ] [ ] [ ] [ ] [ ] Comment [ ] Name * [ ] E-Mail * [ ] [Post Comment] [ ] [ ] [ ] [ ] [ ] [ ] [ ] D[ ] Improve your programming skills Book a scheduled KDAB training! Boost team productivity Book an on-site training! Access KDAB's expertise Book a workshop! [banner-3-218x300] C++ related pages CXX-Qt Loose Coupling with Signals & Slots Introducing KDBindings KDFunctionalSortFilterProxyModel VS Code for Qt Applications - Part 3 The cmake-project Script Fast Duplicate Tracking Improving C++ Development in Visual Studio Code with compile_commands.json and Bear On the Removal of toSet(), toList() and Others State of Native Big File Handling in Git The KDAB Group is the global No.1 software consultancy for Qt, C++ and OpenGL applications across desktop, embedded and mobile platforms * About us + Contact + Customers & Industries + ISO 9001 Certified + Partners + Mission + Working at KDAB + KDAB France + KDAB Japan + Terms and Conditions + Privacy Policy & Cookies * Services + Projects + Workshops + Design Services + Training: On-Site + Training: Scheduled * Expertise + Qt / QML + C++ + 3D / OpenGL * Platforms + Android + Linux + Web integration + QNX + Windows Embedded + Mobile iOS/Android + Windows + macOS + Unix / X11 (Motif) * Resources + Blogs + KDAB TV + Monthly Newsletter Digest + Content Library Search + Whitepapers, Brochures & Articles + Success Stories + Conferences + Newsletter + Events + Qt Tools + Qt and CMake resources + Qt Creator Card Contact us DE: +49 30 5213 254 70 US: +1.866.777.5322 FR: +33 4 90 84 08 53 UK: +44 1625 809908 JP: +81 70 4001 0910 Full list, all countries * * [New-QAS-LO] Manage cookie permissions * [ ] * Services + Projects + Workshops * Training + Training: On-Site + Training: Scheduled * Expertise + Qt/QML + C++ + 3D / OpenGL * Platforms * Blogs * Videos + KDAB TV * About Us + Working at KDAB