Qt and Rust

For the past few months I've been working on an application launcher for Linux. This has been my first foray into writing desktop apps for Linux so I didn't have a go to tool set. I wanted to use my current hobby language Rust, so I looked into the existing GUI libraries available on crates.io and looked at existing Rust GUI apps.

The most popular library of the bunch was gtk-rs, the Rust bindings for the GTK toolkit. I'd never used GTK before so there was a learning curve, but I got something working. GTK worked but I found it hard to use, possible due to my lack of experience with the library, so I decided to try something else. Most of the other Rust GUI libraries were very new and unstable, which is a non-starter for me.

The other major GUI framework used besides GTK is Qt; so I looked into that. The first Qt library I found for Rust was rust-qt-binding-generator. With this, I'd write my application logic in Rust, my UI in QML and write a JSON file to define the objects shared between the two. With this library I was able to get my app working but it was far from perfect. Having to maintain two definitions of my UI object was a pain and I couldn't access the parts of Qt the library didn't expose. The later of which was a problem because I needed a mechanism to load icons by name from the icon cache, which Qt provided but I couldn't access.

Enter qmetaobject-rs. A library the exposed, at least part, of the the Qt API using the cpp crate and a lot of marcos. This library had a few advantages over rust-qt-binding-generator: It had a nicer API, I didn't have to maintain a separate definition of my UI object in JSON, and most importantly to me, I could access the part of the Qt API I needed even though it wasn't exposed through the library. This still wasn't perfect, as I needed to write some C++ code and fork qmetaobject to do what I needed but I was able to do it. I plan to try to upstream my changes at some point but I need to polish them up first.

So if you are interested in writing a desktop app in Rust I recommend checking out qmetaobject.