#cxx #lib #qt5 #qt #qt6 #qmlrs #qml #c #headers #q-meta-object

cxx-qt-lib-headers

A small crate for cxx-qt-lib and cxx-qt-build to share cxx-qt-lib's C++ headers

7 releases

0.6.0 Nov 17, 2023
0.5.3 May 19, 2023
0.5.2 Apr 27, 2023
0.5.1 Mar 27, 2023
0.4.0 Oct 28, 2022

#54 in Graphics APIs

Download history 54/week @ 2023-10-30 55/week @ 2023-11-06 77/week @ 2023-11-13 90/week @ 2023-11-20 99/week @ 2023-11-27 46/week @ 2023-12-04 54/week @ 2023-12-11 75/week @ 2023-12-18 84/week @ 2023-12-25 55/week @ 2024-01-01 60/week @ 2024-01-08 109/week @ 2024-01-15 60/week @ 2024-01-22 114/week @ 2024-01-29 95/week @ 2024-02-05 116/week @ 2024-02-12

400 downloads per month
Used in 2 crates

MIT/Apache

10KB
81 lines

CXX-Qt

Github Book status GitHub Workflow Status License (MIT/Apache2.0) REUSE status

Crate Status
cxx-qt docs.rs Crates.io
cxx-qt-build docs.rs Crates.io
cxx-qt-lib docs.rs Crates.io
qt-build-utils docs.rs Crates.io

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 tested on CI on Linux, Windows, and macOS (all on x86_64). It should work on other platforms that Qt and Rust both support, however, these are not tested regularly.

CXX-Qt is in early development and the API changes frequently. For the latest documentation between releases, install mdBook and run mdbook serve --open in the book folder. It will open your own browser. If you need to open it in another browser goto url http://localhost:3000.

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

Clone the Git repository

This repository contains symbolic links, which requires some setup on Windows 10 before cloning the repository. First, enable Windows Developer Mode to avoid needing administrator privileges to create symlinks. Then, enable symlinks in Git:

git config --global core.symlinks true

Now clone the Git repository:

git clone https://github.com/KDAB/cxx-qt.git

Building

Ensure that you have the following installed

This repository's build system uses CMake, which calls Cargo under the hood to build all the examples and tests. One example can be built and run with Cargo directly without using CMake: cargo run -p qml-minimal-no-cmake (this example is also built in the CMake build). This example does not link with GNU ld.bfd which is the default linker on most Linux distributions; installing mold, lld, or GNU ld.gold (from GNU binutils but may be separate package) is required on Linux.

On Windows and macOS vcpkg can be used by adding -D VCPKG=ON to the CMake configure step to automatically download release mode packages from GitHub Packages (this will take several minutes the first time you run CMake). Note that debug symbols are not built in these packages.

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 USE_QT5=ON to the CMake configure step.

cmake -S . -B build
cmake --build build

Run the basic QML example

./build/examples/qml_minimal/example_qml_minimal

Testing

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 are installed.

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

ctest --test-dir build

Licensing

CXX-Qt is Copyright (C) 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.

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.


lib.rs:

This crate is a hack so build.rs for cxx-qt-lib and cxx-qt-build both have access to cxx-qt-lib's C++ headers. This must be a separate crate from cxx-qt-lib because cxx-qt-lib cannot be a build dependency of cxx-qt-build. Otherwise Cargo links the executable compiled from a build.rs that uses cxx-qt-build to Qt, so running build.rs fails when Qt is linked dynamically if the Qt libraries are not in PATH (Windows)/LD_LIBRARY_PATH (Unix).

No runtime deps

Features