Sign up for the KDAB Newsletter
Stay on top of the latest news, publications, events and more.
Go to Sign-up
We just released CXX-Qt version 0.4!
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.4, most of the internals of CXX-Qt have been refactored into stages, which means it is easier to maintain. There are various small changes to the API, such as the capability of using attributes in more places rather than magic struct names. Relocatable Qt types have been marked as trivial to CXX (which means they don't need to be wrapped in pointers).
Some of the larger developer-facing changes are listed below.
You can now combine CXX definitions into the CXX-Qt bridge macro.
This allows you to define custom types with CXX extern blocks that can then be used for CXX-Qt purposes, such as properties, invokables, and signals.
For example, in the bridge below, a CXX extern "C++" block is used to define QString as a type. Then, this can be used as a property in the QObject definition.
#[cxx_qt::bridge]
mod my_object {
unsafe extern "C++" {
include!("cxx-qt-lib/qstring.h");
type QString = cxx_qt_lib::QString;
}
#[cxx_qt::qobject]
#[derive(Default)]
pub struct MyObject {
#[qproperty]
number: i32,
#[qproperty]
string: QString,
}
}
Custom CMake files have been removed from the build process; Corrosion is used instead, for CMake builds. This allows for a cleaner build that configures and builds Rust code at the correct times.
There is also support for Cargo-only builds for Rust developers who don't use CMake.
Rust closures can now be used to queue tasks onto the Qt event loop from a Rust background thread. This allows you to capture items rather than use a channel with function pointers, as we did in the previous release.
Thanks to Yuya Nishihara for this contribution.
// In an invokable request a handle to the qt thread
let qt_thread = self.qt_thread();
// Spawn a Rust thread
std::thread::spawn(move || {
let value = compute_value_on_rust_thread();
// Use a closure to move the value and run the task on the Qt event loop
qt_thread
.queue(move |mut qobject| {
// Happens on the Qt event loop
qobject.set_value(value);
})
.unwrap();
});
Find CXX-Qt on our GitHub page.
We also have a Rust book with a getting started guide.
Discussions and contributions are welcome, as the API continues evolving for 0.5. With 0.5, we hope to improve the ability to implement listmodels from Rust and introduce Qt container types.
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
Learn Modern C++
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.
Learn more
3 Comments
26 - Nov - 2022
AdamSmith
To use this tool, a user has to master 1.C++, 2. Rust, 3.Qt.
The bar is too high.
1 - Feb - 2023
Andrew Hayzen
Hi Adam,
Yes we understand that this is an advanced tool. It is aimed at established Qt developers who also have some knowledge of Rust and want to join the two ecosystems in their application. To make things simpler for Rust developers we also hope to reduce the amount of C++ you need to write, allow you to build with cargo only, and improve documentation and examples. But otherwise we are dealing with complex languages and tools so unfortunately it is going to require some understanding of either side of the bridge.
Thanks,
Andrew
15 - Feb - 2023
DooMWhite
Anyhow, I'm happy that at least someone is trying to make it possible.