Rust Qt Binding Generator

2017-09-03

This blog post is the announcement of Rust Qt Binding Generator. The project is under review for inclusion in KDE. You can get the source code here.

Scroll to the bottom for the screenshots.

Rust Qt Binding Generator (Logo by Alessandro Longo)

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.

Here is a small schematic of how files made by the generator are related:

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.

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

Comments

Post a comment

Rust Qt Binding Generator

Really cool project. I tested the code in your repo and it compiled flawless. I hope i can find some time on the weekends to dig a little deeper and try some little examples myself.

Reply to this comment

Rust Qt Binding Generator

That's great to hear. A KDE contributor managed to run in FreeBSD. I've not heard from people targeting Mac OS X, Windows, Android or iOS yet, but this approach should also work on those platforms.

Reply to this comment

Rust Qt Binding Generator

I tried building on Windows and since Windows doesn't have pthreads it fails to build.

Here is the error from CMakeError.log

C:\Users\wasim\Documents\src\rust-qt-binding-generator\build\CMakeFiles\CMakeTmp\CheckIncludeFile.c(1): fatal error C1083: Cannot open include file: 'pthread.h': No such file or directory [C:\Users\wasim\Documents\src\rust-qt-binding-generator\build\CMakeFiles\CMakeTmp\cmTC_5e7c3.vcxproj] Done Building Project "C:\Users\wasim\Documents\src\rust-qt-binding-generator\build\CMakeFiles\CMakeTmp\cmTC_5e7c3.vcxproj" (default targets) -- FAILED.

Reply to this comment

Rust Qt Binding Generator

Great to see some more activity on Qt <> Rust! Some questions:

* Is there a public bugtracker?

* Is there any relationship with https://github.com/rust-qt/cpp_to_rust and https://github.com/White-Oak/qml-rust ? How does it compare (feature-set, technical choices...)?

* I heard there was some complexity around implemeting some advanced Qt features related to signals/slots and custom Qml classes, did this lib solve them?

Reply to this comment

Rust Qt Binding Generator

* Is there a public bugtracker?

Not yet, it's requested and will appear at https://bugs.kde.org

* Is there any relationship with cpp_to_rust and qml-rust?

None.

* I heard there was some complexity...

This binding generator is meant exactly to create custom QObjects that are implemented in Rust. In fact, that is all it does. The UI of your application will be writting in QML or C++. This lets you use each language where it shines. Qt and QML for writing nice user interface and Rust for the hard work.

Reply to this comment

Rust Qt Binding Generator

This is pretty nice, I personally could probably work with that, but I am pretty sure the "JSON" indirection could be removed by using Rust macros 1.1/2.0. I would like to look into the project, but it not being on GitHub, for some reason, is a big repellent for me(new account, limited permissions, limited 3rd party services support, weird workflows, etc...)... :(

Reply to this comment

Rust Qt Binding Generator

Using Rust macros might come. I would certainly consider patches that port to using Rust macros with interest. Personally, I find the current solution of generating from JSON to C++ and Rust with one executable good enough. It's easy enough to add that to your build system.

The KDE community where this project is hosted, is dedicated to creating free software. I am more comfortable with primary hosting at KDE. The code is easy to get via the git url. It is mirrored on GitHub. Patches and bug reports are accepted via the KDE infrastructure.

Reply to this comment

Rust Qt Binding Generator

Came here from golang reddit.

I am planning on making some GUI apps for linux and maybe windows as well. The only real choice until now was to use C/C++. But this project looks pretty good. Time to learn Rust I guess.

Reply to this comment