• Stars
    star
    998
  • Rank 45,938 (Top 1.0 %)
  • Language
    Rust
  • Created almost 3 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Safe interop between Rust and Qt

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 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

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, 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 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) 2022, Klarälvdalens Datakonsult AB, and is available under the terms of the MIT or the Apache-2.0 licenses.

Contact KDAB at [email protected] 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.

More Repositories

1

hotspot

The Linux perf GUI for performance analysis.
C++
4,027
star
2

GammaRay

GammaRay is a tool to poke around in a Qt-application and also to manipulate the application to some extent.
C++
1,410
star
3

codebrowser

Woboq CodeBrowser
C++
1,093
star
4

KDDockWidgets

KDAB's Dock Widget Framework for Qt
C++
623
star
5

android_openssl

OpenSSL scripts and bins for Android (useful for Qt on Android apps)
C
313
star
6

KDToolBox

KDAB's collection of miscellaneous useful C++ classes and stuff
C++
259
star
7

KDBindings

Reactive programming & data binding in C++
C++
208
star
8

Charm

The Cross-Platform Time Tracker
C++
192
star
9

kdabtv

This repository contains the code of the examples showcased in the KDAB TV video series.
C++
186
star
10

DeclarativeWidgets

Library and tools for creating QtWidget UIs using QML
C++
168
star
11

KDStateMachineEditor

A framework for creating Qt State Machine metacode using a graphical user interface
C++
159
star
12

KDSoap

A Qt-based client-side and server-side SOAP component
C++
140
star
13

kuesa

Professional 3D asset creation and integration workflow for Qt
C++
139
star
14

qt3d-examples

Qt3D Examples
C++
131
star
15

KDReports

Qt library for generating printable and exportable reports from code and from XML descriptions.
C++
115
star
16

KDChart

A Qt tool for creating business and scientific charts. This is the canonical repository for KDChart.
C++
99
star
17

KDAlgorithms

Algorithm wrappers
C++
77
star
18

sqlate

C++
58
star
19

android

KDAB's Android gems
C++
45
star
20

KDSingleApplication

KDAB's helper class for single-instance policy applications
CMake
45
star
21

integrating-qq2-with-opengl

C++
43
star
22

virtual-keyboard-demo

Example source code for the implementation of a virtual keyboard based on Qt input method framework
C++
42
star
23

Qt4to5

C++
40
star
24

KDMacTouchBar

KDAB's Qt Widget for the Mac Touch Bar
Objective-C++
37
star
25

KDTools

KDTools aims to ease the daily work of Qt programmers by providing a number of well-designed, easy-to-use widgets and non-gui classes.
C++
30
star
26

FatCRM

Desktop Application for SugarCRM
C++
28
star
27

qsslint

Linter for Qt stylesheet files
C++
21
star
28

ctf2ctf

Common Trace Format to Chrome Trace Format converter
C++
18
star
29

eglinfo

Provides information about available EGL configurations.
C++
16
star
30

perfparser

fork of qt-creator/perfparser.git with not-yet upstreamed changes required for hotspot
C++
15
star
31

GammaRay-plugin-examples

Example plug-ins for GammaRay
C++
14
star
32

homebrew-tap

Homebrew formulas for KDAB projects
Ruby
11
star
33

OpenEmbedded-Archos

An Angstrom distro for the Archos 101IT tablet based on OpenEmbedded, with Qt4 and Qt5 support including multitouch and OpenGL/ES2
C
11
star
34

KDBoatDemo

KDAB Nautical UI - concept of the next generation UI for sailing boats
QML
8
star
35

QMemstat

Inspect Pagemaps of Programs
C++
8
star
36

KDUtils

A set of C++ helpers and wrappers around the C++ standard library
C++
7
star
37

knut

Knut is an automation tool for code transformation using scripts.
C++
5
star
38

autogen

Common build system code for KDAB products
Python
5
star
39

clang-format-rs

clang-format wrapper for rust
Rust
4
star
40

patent_defense

Defensive Patent Publications
C
3
star
41

qnxtools

Python
3
star
42

KDGpu

KDGpu is a thin wrapper around Vulkan to make modern graphics easier to learn and use
C++
3
star
43

WebKit

QtWebkit clone
C++
2
star
44

event_loop_watchdog

A class to detect whenever your main event loop gets blocked for more than x milliseconds
Dart
2
star
45

vscode-qttest

VSCode extension for supporting Qt tests in the "Testing" sidebar
TypeScript
2
star
46

cabin-demo

KDAB Flutter demo application.
Dart
1
star
47

GammaRayPlatformProbe

GammaRay Platform Probe
C++
1
star
48

kdab-overlay

Gentoo Portage overlay containing KDAB software
Shell
1
star
49

kuserfeedbackdocker

Docker container for the KUserFeedback server.
PHP
1
star
50

unicode_view

Playground repo for unicode view
C++
1
star
51

blog-vscode-template

vscode template for C++ projects (Cross referenced by the blog, do not delete)
CMake
1
star