• Stars
    star
    788
  • Rank 55,443 (Top 2 %)
  • Language
    Rust
  • License
    GNU General Publi...
  • Created over 6 years ago
  • Updated 11 months ago

Reviews

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

Repository Details

Generate bindings to use Rust code in Qt and QML

Rust Qt Binding Generator

Rust Qt Binding

This code generator gets you started quickly to use Rust code from Qt and QML. In other words, it helps to create a Qt based GUI on top of Rust code.

Qt is a mature cross-platform graphical user interface library. Rust is a new programming language with strong compile time checks and a modern syntax.

Getting started

There are two template projects that help you to get started quickly. One for Qt Widgets and one for Qt Quick. Just copy these folders as new project and start coding.

Qt Widgets (main.cpp) / Qt Quick (main.qml) โŸต UI code, written by hand
src/Binding.h โŸต generated from binding.json
src/Binding.cpp
rust/src/interface.rs
rust/src/implementation.rs โŸต Rust code, written by hand

To combine Qt and Rust, write an interface in a JSON file. From that, the generator creates Qt code and Rust code. The Qt code can be used directly. The Rust code has two files: interface and implementation. The interface can be used directly.

{
    "cppFile": "src/Binding.cpp",
    "rust": {
        "dir": "rust",
        "interfaceModule": "interface",
        "implementationModule": "implementation"
    },
    "objects": {
        "Greeting": {
            "type": "Object",
            "properties": {
                "message": {
                    "type": "QString",
                    "write": true
                }
            }
        }
    }
}

This file describes an binding with one object, Greeting. Greeting has one property: message. It is a writable property.

The Rust Qt Binding Generator will create binding source code from this description:

rust_qt_binding_generator binding.json

This will create four files:

  • src/Binding.h
  • src/Binding.cpp
  • rust/src/interface.rs
  • rust/src/implementation.rs

Only implementation.rs should be changed. The other files are the binding. implementation.rs is initialy created with a simple implementation that is shown here with some comments.

use interface::*;

/// A Greeting
pub struct Greeting {
    /// Emit signals to the Qt code.
    emit: GreetingEmitter,
    /// The message of the person.
    message: String,
}

/// Implementation of the binding
/// GreetingTrait is defined in interface.rs
impl GreetingTrait for Greeting {
    /// Create a new greeting with default data.
    fn new(emit: GreetingEmitter) -> Greeting {
        Greeting {
            emit: emit,
            message: "Hello World!",
        }
    }
    /// The emitter can emit signals to the Qt code.
    fn emit(&self) -> &GreetingEmitter {
        &self.emit
    }
    /// Get the message of the Greeting
    fn message(&self) -> &str {
        &self.message
    }
    /// Set the message of the Greeting
    fn set_message(&mut self, value: String) {
        self.message = value;
        self.emit.message_changed();
    }
}

The building block of Qt and QML projects are QObject and the Model View classes. rust_qt_binding_generator reads a json file to generate QObject or QAbstractItemModel classes that call into generated Rust files. For each type from the JSON file, a Rust trait is generated that should be implemented.

This way, Rust code can be called from Qt and QML projects.

Qt Widgets with Rust

This C++ code uses the Rust code written above.

#include "Binding.h"
#include <QDebug>
int main() {
    Greeting greeting;
    qDebug() << greeting.message();
    return 0;
}

Qt Quick with Rust

This Qt Quick (QML) code uses the Rust code written above.

Rectangle {
    Greeting {
        id: rust
    }
    Text {
        text: rust.message
    }
}

Demo application

The project comes with a demo application that show a Qt user interface based on Rust. It uses all of the features of Object, List and Tree. Reading the demo code is a good way to get started.

Qt Widgets UI with Rust logic

Qt Widgets UI with Rust logic

Qt Quick Controls UI with Rust logic

Qt Quick Controls UI with Rust logic

Qt Quick Controls 2 UI with Rust logic

Qt Quick Controls 2 UI with Rust logic

Docker development environment

To get started quickly, the project comes with a Dockerfile. You can start a docker session with the required dependencies with ./docker/docker-bash-session.sh.

More information on Qt

Tutorials

Presentation

Information on Qt

Issues

Please report bugs and feature requests in the KDE issue tracker, product "rust-qt-binding-generator".

More Repositories

1

krita

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
5,850
star
2

ghostwriter

Text editor for Markdown
C++
4,121
star
3

heaptrack

A heap memory profiler for Linux
C++
2,954
star
4

kdenlive

Free and open source video editor, based on MLT Framework and KDE Frameworks 5
C++
2,439
star
5

kdeconnect-kde

Multi-platform app that allows your devices to communicate
C++
2,171
star
6

latte-dock

Replacement dock for Plasma desktops, providing an elegant and intuitive experience for your tasks and plasmoids
C++
1,474
star
7

kdeconnect-android

Native Android port of the KDE Connect Qt app
Java
774
star
8

plasma-desktop

Plasma for the Desktop
C++
692
star
9

okular

KDE document viewer
C++
632
star
10

clazy

Qt-oriented static code analyzer based on the Clang framework
C++
609
star
11

kate

Modern text editor built on the KDE Frameworks and Qt
C++
558
star
12

digikam

digiKam is an advanced open-source digital photo management application that runs on Linux, Windows, and MacOS. The application provides a comprehensive set of tools for importing, managing, editing, and sharing photos and raw files.
C++
507
star
13

kdevelop

Cross-platform IDE for C, C++, Python, QML/JavaScript and PHP
C++
434
star
14

kwin

Easy to use, but flexible, X Window Manager and Wayland Compositor
C++
427
star
15

konsole

Terminal emulator by KDE
C++
418
star
16

dolphin

File manager by KDE
C++
400
star
17

kdiff3

Utility for comparing and merging files and directories
C++
332
star
18

yakuake

Drop-down terminal emulator based on Konsole technologies
C++
330
star
19

kcachegrind

GUI to profilers such as Valgrind
C++
326
star
20

falkon

Cross-platform Qt-based web browser
C++
324
star
21

kdeconnect-ios

Native iOS port of KDE Connect
Swift
313
star
22

snoretoast

Command-line application capable of creating Windows Toast notifications
C++
280
star
23

massif-visualizer

Visualizer for Valgrind Massif data files
C++
267
star
24

elisa

Simple music player aiming to provide a nice experience for its users
C++
238
star
25

breeze-icons

Breeze icon theme.
C++
217
star
26

kirigami

A QtQuick based components set
QML
208
star
27

breeze

Artwork, styles and assets for the Breeze visual style for the Plasma Desktop
C++
192
star
28

plasma-workspace

Various components needed to run a Plasma-based environment
C++
191
star
29

kstars

Desktop Planetarium
C++
191
star
30

spectacle

Screenshot capture utility
C++
179
star
31

labplot

LabPlot is a FREE, open source and cross-platform Data Visualization and Analysis software accessible to everyone.
C++
177
star
32

amarok

Powerful music player that lets you rediscover your music
C++
153
star
33

kube

Modern groupware client based on QtQuick and Sink
C++
152
star
34

calligra

Office and graphic art suite by KDE
C++
144
star
35

khtml

KHtml
136
star
36

plasma-mobile

Plasma shell for mobile devices
QML
132
star
37

plasma-framework

Plasma library and runtime components
C++
130
star
38

snorenotify

Multi-platform Qt notification framework
C++
128
star
39

syntax-highlighting

Syntax highlighting Engine for Structured Text and Code.
HTML
128
star
40

krusader

Advanced twin panel (commander style) file manager
C++
123
star
41

k3b

Full-featured CD/DVD/Blu-ray burning and ripping application
C++
118
star
42

marble

Virtual Globe and World Atlas that you can use to learn more about the Earth
C++
117
star
43

kmymoney

Personal finance manager
C++
114
star
44

neochat

A client for matrix, the decentralized communication protocol
C
113
star
45

extra-cmake-modules

Extra modules and scripts for CMake.
CMake
113
star
46

umbrello

GUI for diagramming Unified Modelling Language (UML)
C++
105
star
47

plasma-workspace-wallpapers

Wallpapers for Plasma Workspaces
CMake
103
star
48

plasma-browser-integration

Components necessary to integrate browsers into the Plasma Desktop
JavaScript
100
star
49

gwenview

Image viewer by KDE
C++
93
star
50

kdeplasma-addons

All kind of add-ons to improve your Plasma experience
C++
85
star
51

okteta

Hex editor for viewing and editing the raw data of files
C++
85
star
52

plasma-bigscreen

Plasma shell for TVs
QML
84
star
53

kalendar

A calendar application using Akonadi to sync with external services (Nextcloud, GMail, ...)
C++
81
star
54

kio-gdrive

KIO Slave to access Google Drive
C++
80
star
55

wacomtablet

GUI for Wacom Linux drivers that supports different button/pen layout profiles
C++
79
star
56

kleopatra

Certificate manager and GUI for OpenPGP and CMS cryptography
C++
79
star
57

kolourpaint

Easy-to-use paint program
C++
78
star
58

qca

Qt Cryptographic Architecture โ€” straightforward cross-platform crypto API
C++
76
star
59

discover

KDE and Plasma resources management GUI
C++
75
star
60

ark

File archiver by KDE
C++
72
star
61

qqc2-desktop-style

Qt Quick Controls 2: Desktop Style
QML
71
star
62

krunner

Framework for providing different actions given a string query.
C++
69
star
63

kile

Integrated LaTeX Editing Environment
HTML
69
star
64

breeze-gtk

Breeze widget theme for GTK 2 and 3
SCSS
66
star
65

liquidshell

Basic desktop shell using QtWidgets
C++
65
star
66

ring-kde

Qt-based Ring communication framework (www.ring.cx) client
QML
64
star
67

ktexteditor

KTextEditor Framework
C++
64
star
68

ktorrent

Powerful BitTorrent client
C++
64
star
69

konqueror

Web browser and Swiss Army knife for any kind of file management and previewing
C++
63
star
70

ktouch

Touch Typing Tutor
C++
61
star
71

kio

KIO
C++
60
star
72

kmail

State-of-the-art feature-rich email client that supports many protocols
C++
60
star
73

vvave

Multi-platform media player
C++
58
star
74

baloo

Baloo is a framework for searching and managing metadata.
C++
56
star
75

craft

Open source meta build system and package manager
Python
55
star
76

haruna

Open source video player built with Qt/QML and libmpv.
QML
53
star
77

kid3

Efficient audio tagger that supports a large variety of file formats
C++
52
star
78

partitionmanager

Manage the disk devices, partitions and file systems on your computer
C++
51
star
79

cantor

Front end to powerful mathematics and statistics packages
Jupyter Notebook
48
star
80

kscreen

KDE's screen management software
C++
46
star
81

plasma-vault

Plasma applet and services for creating encrypted vaults
C++
46
star
82

ksshaskpass

ssh-add helper that uses KWallet and KPasswordDialog
C++
44
star
83

xdg-desktop-portal-kde

A backend implementation for xdg-desktop-portal that is using Qt/KDE
C++
44
star
84

kbibtex

An editor for bibliographies used with LaTeX
C++
43
star
85

kwayland

KWayland provides a Qt-style Client and Server library wrapper for the Wayland libraries.
C++
43
star
86

krdc

Remote Desktop Client
C++
42
star
87

konversation

User-friendly and fully-featured IRC client
C++
42
star
88

qtcurve

Style engine for Qt and other toolkits
C++
42
star
89

systemsettings

Control center to configure your Plasma Desktop
C++
42
star
90

akregator

RSS Feed Reader
C++
40
star
91

plasma-nm

Plasma applet written in QML for managing network connections
C++
40
star
92

ksysguard

Resource usage monitor for your computer
C
40
star
93

kdev-rust

KDevelop plugin which provides Rust language support.
C++
39
star
94

plasma-systemmonitor

An interface for monitoring system sensors, process information and other system resources
QML
39
star
95

kjs

KJS
39
star
96

minuet

Free and open-source software for music education
C++
39
star
97

docker-neon

Docker packaging environment for KDE Neon
Ruby
38
star
98

elf-dissector

Tools for inspecting, analyzing and optimizing ELF files
C++
38
star
99

ruqola

KDE client for Rocket Chat
C++
38
star
100

libqgit2

Qt wrapper library around the libgit2 git access library
C++
37
star