Sign up for the KDAB Newsletter
Stay on top of the latest news, publications, events and more.
Go to Sign-up
Leon Matthes,
Andrew Hayzen
24 November 2023
We just released CXX-Qt version 0.6!
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.6, we're excited to announce that we're on the road to stabilization! 🥳
We've done a (hopefully final) iteration of our API and are now happier than ever to release it.
The new API is now truly in the spirit of CXX.
All implementation has moved out of the #[cxx_qt::bridge]
and is now simply outside the bridge, like it is for CXX as well.
To get an overview of the new API, check out our the planned 1.0 API, which is available starting with this release.
Check out the new release through the usual channels:
Some of the more extensive developer-facing changes are listed below.
Like extern "C++"
in CXX, the extern "C++Qt"
block now only uses a declaration-like syntax to expose functionality to C++/Qt.
This is an extension to CXX's extern "C++"
blocks, which allow defining methods as #[qsignal]
.
These signals can then be emitted from Rust, as well as connected to.
Like extern "Rust"
in CXX, the extern "RustQt"
block now only uses a declaration-like syntax to expose functionality to C++/Qt.
Most existing features have moved to an attribute-syntax, which should look very familiar to existing Qt developers.
The new API includes:
#[qobject]
is now on a type alias to distinguish between QObject and Rust struct clearer#[qproperty(...)]
is now just an attribute on the #[qobject]
#[inherit]
,#[qsignal]
& #[qinvokable]
have now moved to attributes of external function declarations. They can also now be freely mixed#[cxx_override]
, #[cxx_final]
, #[cxx_virtual]
are now independent attributes rather than imbedded in #[qinvokable]
Like shared types in CXX, enums for Qt can be declared using a shared enum in the bridge.
These can be defined using the #[qenum]
attribute and qnamespace!(...)
macro.
Like CXX the implementations on types are now defined outside of the bridge rather than inside.
This allows you to choose the prefix for QObjects, as the hard-coded qobject::
prefix is now simply the name of the #[cxx_qt::bridge]
module.
Another great new feature in this release: Connecting to Signals via Rust is now possible!
Simply use the on_[SIGNAL-NAME]
/connect_[SIGNAL-NAME]
methods generated for each signal.
Closures are supported when connecting to signals as well.
The build system has been improved so that QML modules can now be output by CXX-Qt. This allows for using the declarative syntax of #[qml_element]
and #[qml_singleton]
on a #[qobject]
, whereas before Rust QObject types needed to be registered in C++ with the QML engine.
use cxx_qt_build::{CxxQtBuilder, QmlModule};
fn main() {
CxxQtBuilder::new()
.qml_module(QmlModule {
uri: "com.kdab.cxx_qt.demo",
rust_files: &["src/cxx_qt_bridge.rs"],
qml_files: &["qml/main.qml"],
..Default::default()
})
.build();
}
This should also allow for tooling to inspect QML modules that were generated from Rust in the future.
Most features of the CXX-Qt code generation are now expressed through Rust traits and can be enabled/disabled or otherwise configured using a syntax similar to CXX shim trait impls.
New features
cxx_qt::Constructor
- this drops the requirement for Default
on the Rust struct.cxx_qt::Initialize
.cxx_qt::CxxQtType
trait for reflection and less "magic" methods.Existing features that can now be enabled/disabled:
cxx_qt::Threading
trait.cxx_qt::Locking
trait.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