4 releases (2 breaking)

0.3.0 Jun 10, 2022
0.2.1 Mar 21, 2022
0.2.0 Feb 28, 2022
0.1.0 Dec 3, 2021

#92 in Build Utils

22 downloads per month



Rust 7K SLoC // 0.1% comments C++ 1K SLoC // 0.0% comments


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 used to build Rust applications with Cargo. CXX-Qt provides tools for implementing QObject subclasses in Rust which can be used from C++, QML, and JavaScript. It consists of two parts:

  • cxx-qt-lib, a library of Rust bindings to common QtCore and QtGui classes made with CXX

  • cxx-qt & cxx-qt-build, a pair of Rust & C++ code generators which are a superset of CXX plus additional attributes to interface with Qt's signals & slots and property system. The cxx-qt crate implements a macro for Rust code generation. cxx-qt-build is used in Cargo build scripts to generate and compile the corresponding C++ code.

The CXX-Qt Book walks through a minimal example step-by-step and documents CXX-Qt's features for the latest release. The examples folder contains demonstrations of using threading, QQmlExtensionPlugin, and various other features.

CXX-Qt is in early development and the API changes frequently. For the latest documentation, install mdBook and run mdbook serve in the book folder.

Comparison to other Rust Qt bindings

Project Integrate into C++ codebase Safe Rust QML QWidgets Maintained1 Binding mechanism
CXX-Qt limited2 cxx plus additional code generation to implement QObject subclasses in Rust and bind them to C++
qmetaobject cpp macro to write C++ inline in Rust, plus Rust macros to create QObject subclasses from Rust structs
Rust Qt Binding Generator limited2 generates Rust traits and C++ bindings from JSON description of QObject subclass
rust-qt ritual to generate unsafe Rust bindings from C++ headers
qml-rust DOtherSide C wrapper for QML C++ classes
qmlrs own C++ library to bind QQmlApplicationEngine
qmlrsng libqmlbind with bindgen
rust-qml libqmlbind

1: maintained: supports Qt6 and repository has had nontrivial commits within last year as of August 2022

2: CXX-Qt and Rust Qt Binding Generator can be used to implement custom QObjects subclasses in Rust. C++ bindings for these QObject subclasses can be used in QWidgets applications, but these projects do not provide Rust bindings for QWidgets APIs.

Contributing to CXX-Qt


Ensure that you have the following installed


In a CXX-Qt project, the build system is based on CMake, which uses Cargo under the hood. Therefore, unlike a typical Rust project, CMake must be used to build CXX-Qt.

On Windows and macOS, CXX-Qt defaults to installing Qt from vcpkg. Prebuilt packages are automatically downloaded from GitHub Packages (this will take several minutes the first time you run CMake). If you already have Qt installed, you can disable this by adding -D VCPKG=OFF to the CMake configure step (the first call to cmake).

CXX-Qt defaults to building with Qt6. If you want to build with Qt5 when both are installed, or you want to tell vcpkg to use Qt5, add -D QT_DEFAULT_MAJOR_VERSION=5 to the CMake configure step.

mkdir build/
cd build/
cmake ../
cmake --build . -j$(nproc)

Run the basic QML example



You can build the book using mdbook serve from the book folder, you should install mdbook and mdbook-linkcheck from cargo.


Testing assumes that cargo clippy and cargo fmt are available, you may need to install these with rustup component add clippy rustfmt.

For testing the book, it assumes that mdbook and mdbook-linkcheck from cargo have been installed.

For license and memory testing, it assumes that you have reuse installed (eg via pip3 install reuse) and valgrind.

cd build/
ctest -j$(nproc)


CXX-Qt is Copyright (C) 2021, Klarälvdalens Datakonsult AB, and is available under the terms of the MIT or the Apache-2.0 licenses.

Contact KDAB at info@kdab.com to inquire about additional features or services related to this project.

CXX-Qt includes these source files, also available under the terms of the MIT license:

The following CMake source files are available under the BSD-3-Clause

About KDAB

CXX-Qt is supported and maintained by Klarälvdalens Datakonsult AB (KDAB).

The KDAB Group is the global No.1 software consultancy for Qt, C++ and OpenGL applications across desktop, embedded and mobile platforms.

The KDAB Group provides consulting and mentoring for developing Qt applications from scratch and in porting from all popular and legacy frameworks to Qt. We continue to help develop parts of Qt and are one of the major contributors to the Qt Project. We can give advanced or standard trainings anywhere around the globe on Qt as well as C++, OpenGL, 3D and more.

Please visit https://www.kdab.com to meet the people who write code like this.


~52K SLoC