{"id":13648826,"url":"https://github.com/KDE/rust-qt-binding-generator","last_synced_at":"2025-04-22T11:33:21.309Z","repository":{"id":43522956,"uuid":"102454923","full_name":"KDE/rust-qt-binding-generator","owner":"KDE","description":"Generate bindings to use Rust code in Qt and QML","archived":false,"fork":false,"pushed_at":"2024-09-06T02:45:23.000Z","size":1140,"stargazers_count":810,"open_issues_count":0,"forks_count":35,"subscribers_count":33,"default_branch":"master","last_synced_at":"2025-04-12T16:59:02.923Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://invent.kde.org/sdk/rust-qt-binding-generator","language":"Rust","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KDE.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog","contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-09-05T08:24:08.000Z","updated_at":"2025-04-04T03:12:14.000Z","dependencies_parsed_at":"2023-10-17T11:50:19.532Z","dependency_job_id":"2615a1f1-c1b9-4b8e-85c8-d5d253072ee5","html_url":"https://github.com/KDE/rust-qt-binding-generator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KDE%2Frust-qt-binding-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KDE%2Frust-qt-binding-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KDE%2Frust-qt-binding-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KDE%2Frust-qt-binding-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KDE","download_url":"https://codeload.github.com/KDE/rust-qt-binding-generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250232559,"owners_count":21396662,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T01:04:34.735Z","updated_at":"2025-04-22T11:33:20.940Z","avatar_url":"https://github.com/KDE.png","language":"Rust","funding_links":[],"categories":["Rust","GUI"],"sub_categories":[],"readme":"# Rust Qt Binding Generator\n\n![Rust Qt Binding](demo/rust_qt_binding_generator.svg)\n\nThis 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.\n\nQt is a mature cross-platform graphical user interface library. Rust is a new programming language with strong compile time checks and a modern syntax.\n\n## Getting started\n\nThere are two template projects that help you to get started quickly. One for [Qt Widgets](templates/qt_widgets) and one for [Qt Quick](templates/qt_quick). Just copy these folders as new project and start coding.\n\n\n\u003ctable style=\"font-size: larger\"\u003e\n \u003ctr\u003e\n  \u003ctd style=\"background:#676767; color: white\"\u003eQt Widgets (main.cpp) / Qt Quick (main.qml)\u003c/td\u003e\n  \u003ctd\u003e\u0026#10229; UI code, written by hand\u003c/td\u003e\n \u003c/tr\u003e\n \u003ctr\u003e\n  \u003ctd style=\"background:#3daefd\"\u003esrc/Binding.h\u003c/td\u003e\n  \u003ctd rowspan=\"3\" style=\"valign: center\"\u003e\u0026#10229; generated from binding.json\u003c/td\u003e\n \u003c/tr\u003e\n \u003ctr\u003e\n  \u003ctd style=\"background:#3daefd\"\u003esrc/Binding.cpp\u003c/td\u003e\n \u003c/tr\u003e\n \u003ctr\u003e\n  \u003ctd style=\"background:#3daefd\"\u003erust/src/interface.rs\u003c/td\u003e\n \u003c/tr\u003e\n \u003ctr\u003e\n  \u003ctd style=\"background:#676767; color: white\"\u003erust/src/implementation.rs\u003c/td\u003e\n  \u003ctd\u003e\u0026#10229; Rust code, written by hand\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/table\u003e\n\nTo 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.\n\n```json\n{\n    \"cppFile\": \"src/Binding.cpp\",\n    \"rust\": {\n        \"dir\": \"rust\",\n        \"interfaceModule\": \"interface\",\n        \"implementationModule\": \"implementation\"\n    },\n    \"objects\": {\n        \"Greeting\": {\n            \"type\": \"Object\",\n            \"properties\": {\n                \"message\": {\n                    \"type\": \"QString\",\n                    \"write\": true\n                }\n            }\n        }\n    }\n}\n```\n\nThis file describes an binding with one object, `Greeting`. `Greeting` has one property: `message`. It is a writable property.\n\nThe Rust Qt Binding Generator will create binding source code from this description:\n\n```bash\nrust_qt_binding_generator binding.json\n```\n\nThis will create four files:\n\n* *src/Binding.h*\n* *src/Binding.cpp*\n* *rust/src/interface.rs*\n* rust/src/implementation.rs\n\nOnly `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.\n\n```rust\nuse interface::*;\n\n/// A Greeting\npub struct Greeting {\n    /// Emit signals to the Qt code.\n    emit: GreetingEmitter,\n    /// The message of the person.\n    message: String,\n}\n\n/// Implementation of the binding\n/// GreetingTrait is defined in interface.rs\nimpl GreetingTrait for Greeting {\n    /// Create a new greeting with default data.\n    fn new(emit: GreetingEmitter) -\u003e Greeting {\n        Greeting {\n            emit: emit,\n            message: \"Hello World!\",\n        }\n    }\n    /// The emitter can emit signals to the Qt code.\n    fn emit(\u0026self) -\u003e \u0026GreetingEmitter {\n        \u0026self.emit\n    }\n    /// Get the message of the Greeting\n    fn message(\u0026self) -\u003e \u0026str {\n        \u0026self.message\n    }\n    /// Set the message of the Greeting\n    fn set_message(\u0026mut self, value: String) {\n        self.message = value;\n        self.emit.message_changed();\n    }\n}\n```\n\nThe 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.\n\nThis way, Rust code can be called from Qt and QML projects.\n\n### Qt Widgets with Rust\n\nThis C++ code uses the Rust code written above.\n\n```cpp\n#include \"Binding.h\"\n#include \u003cQDebug\u003e\nint main() {\n    Greeting greeting;\n    qDebug() \u003c\u003c greeting.message();\n    return 0;\n}\n```\n\n### Qt Quick with Rust\n\nThis Qt Quick (QML) code uses the Rust code written above.\n\n```qml\nRectangle {\n    Greeting {\n        id: rust\n    }\n    Text {\n        text: rust.message\n    }\n}\n```\n\n## Demo application\n\nThe 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.\n\n\u003cfigure\u003e\n  \u003cimg src=\"demo/screenshots/demo.png\" alt=\"Qt Widgets UI with Rust logic\"/\u003e\n  \u003cfigcaption\u003e\u003ca href=\"demo/src/main.cpp\"\u003eQt Widgets UI\u003c/a\u003e with \u003ca href=\"demo/rust/src/implementation/file_system_tree.rs\"\u003eRust logic\u003c/a\u003e\u003c/figcaption\u003e\n\u003c/figure\u003e\n\n\u003cfigure\u003e\n  \u003cimg src=\"demo/screenshots/demo2.png\" alt=\"Qt Quick Controls UI with Rust logic\"/\u003e\n  \u003cfigcaption\u003e\u003ca href=\"demo/qml/DataAndChart.qml\"\u003eQt Quick Controls UI\u003c/a\u003e with \u003ca href=\"demo/rust/src/implementation/time_series.rs\"\u003eRust logic\u003c/a\u003e\u003c/figcaption\u003e\n\u003c/figure\u003e\n\n\u003cfigure\u003e\n  \u003cimg src=\"demo/screenshots/demo3.png\" alt=\"Qt Quick Controls 2 UI with Rust logic\"/\u003e\n  \u003cfigcaption\u003e\u003ca href=\"demo/qml/FileTreeView2.qml\"\u003eQt Quick Controls 2 UI\u003c/a\u003e with \u003ca href=\"demo/rust/src/implementation/file_system_tree.rs\"\u003eRust logic\u003c/a\u003e\u003c/figcaption\u003e\n\u003c/figure\u003e\n\n## Docker development environment\n\nTo 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`.\n\n## More information on Qt\n\n* [Initial blog post](https://www.vandenoever.info/blog/2017/09/04/rust_qt_binding_generator.html)\n\n### Tutorials\n\n* [Rust and QML: a timely example](https://www.vandenoever.info/blog/2017/09/10/time_for_rust_and_qml.html)\n* [To do a Rust GUI](https://www.vandenoever.info/blog/2018/06/09/to-do-a-rust-gui.html)\n* [Browsing your mail with Rust and Qt](https://www.vandenoever.info/blog/2018/09/16/browsing_your_mail_with_rust_and_qt.html)\n\n### Presentation\n\n* [Qt GUIs with Rust](https://archive.fosdem.org/2018/schedule/event/rust_qt_binding_generator/)\n\n### Information on Qt\n\n* [Qt](http://doc.qt.io/)\n* [Qt Examples and tutorials](http://doc.qt.io/qt-5/qtexamplesandtutorials.html)\n* [The QML Book](https://qmlbook.github.io/)\n\n## Issues\n\nPlease [report bugs and feature requests](https://bugs.kde.org/enter_bug.cgi?product=rust-qt-binding-generator) in the KDE issue tracker, product \"rust-qt-binding-generator\".\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKDE%2Frust-qt-binding-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKDE%2Frust-qt-binding-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKDE%2Frust-qt-binding-generator/lists"}