Sign up for the KDAB Newsletter
Stay on top of the latest news, publications, events and more.
Go to Sign-up
Andrew Hayzen
9 March 2023
We just released CXX-Qt version 0.5!
CXX-Qt is a set of Rust crates for creating bidirectional Rust ⇄ C++ bindings with Qt. It can be used to integrate Rust into C++ applications using CMake or build Rust applications with Cargo. CXX-Qt provides tools for implementing QObject subclasses in Rust that can be used from C++, QML, and JavaScript.
For 0.5, the focus has mainly been on adding more common Qt types, support for Qt container types, support for pointer types, and improving inheritance. Simple QML applications can now be written entirely in Rust, including implementing Qt models, without needing any boilerplate C++ code.
Some of the more extensive developer-facing changes are listed below.
This release introduces new features for interfacing with C++ inheritance from Rust. These allow you to implement subclasses in Rust without needing to write boilerplate C++ code.
When subclassing some Qt classes, you need to call methods of the base class, for example QAbstractItemModel::beginInsertRows, without necessarily overriding those methods in your subclass. A new macro #[cxx_qt::inherit]
can be used on extern "C++"
blocks to create Rust bindings to those methods inherited from the C++ base class.
There is also an #[inherit]
macro that can be used to access signals inherited from the base class. This tells CXX-Qt to skip generating a new Q_SIGNAL
and to use the base class version instead.
Bindings for more Qt types have been added to cxx-qt-lib
:
We have also added support for Qt container types:
QList and QVector can easily be converted from Rust slices and into Rust Vecs.
Many Qt types in cxx-qt-lib now have common Rust standard library traits implemented, such as Default, Display, Debug, PartialEq, Eq, PartialOrd, Ord, and arithmetic operators (Add, Sub, Mul, Div traits).
Cargo features have been added to cxx-qt-lib for easily converting between Qt types and types from widely used Rust crates:
The code generator now supports pointer types such as *mut T
to refer to another Rust QObject
in properties, signals, and invokables.
The build system can now register files from the Qt Resource System at build time, so calling a C++ function to initialize them is no longer needed. Likewise, QML types can now be registered at build time, instead of calling qmlRegisterType
from C++ code. Together with new bindings for QGuiApplication and QQmlApplicationEngine, there is no longer a need for boilerplate C++ code to launch a QML application from Rust. The API is still evolving and we hope to improve this area in the next release to support the new ahead-of-time QML compilation tools.
Find CXX-Qt on our GitHub repository and view our CHANGELOG for more details about the changes.
We also have a book with a getting started guide.
Discussions and contributions are welcome on GitHub!
About KDAB
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.
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
Learn Rust
In collaboration with our partners Ferrous Systems, KDAB provides a variety of introductory and advanced training courses for the Rust language.
Learn more