MCPcopy Index your code
hub / github.com/cyndis/qmlrs

github.com/cyndis/qmlrs @v0.1.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.1.1 ↗ · + Follow
89 symbols 136 edges 15 files 1 documented · 1%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

qmlrs - QtQuick bindings for Rust

Travis Build Status Coverage Status MIT licensed Apache licensed crates.io

Image of example

qmlrs allows the use of QML/QtQuick code from Rust, specifically

  • Rust code can create a QtQuick engine (QQmlApplicationEngine) with a loaded QML script
  • QML code can invoke Rust functions

…with certain limitations. The library should be safe (as in not unsafe) to use, but no promises at this time. Reviews of the code would be welcome.

News

See the Changelog for the version history and what's waiting in master to be released.

Requirements

The library consists of a Rust part and a C++ part. The C++ part will be compiled automatically when building with Cargo. You will need cmake, Qt5 and a C++ compiler that can compile Qt5 code. Your Qt5 installation should have at least the following modules: Core, Gui, Qml, Quick and Quick Controls.

If you are installing Qt5 from source, please note that passing "-noaccessibility" to the configure script disables the qtquickcontrols module.

Usage

Add the latest version of qmlrs from crates.io in your project's Cargo.toml.

Example

This is the Rust code for an application allowing the calculation of factorials. You can find the corresponding QML code in the examples directory.

#[macro_use]
extern crate qmlrs;

struct Factorial;
impl Factorial {
    fn calculate(&self, x: i64) -> i64 {
        std::iter::range_inclusive(1, x).fold(1, |t,c| t * c)
    }
}

Q_OBJECT! { Factorial:
    slot fn calculate(i64);
}

fn main() {
    let mut engine = qmlrs::Engine::new();

    engine.set_property("factorial", Factorial);
    engine.load_local_file("examples/factorial_ui.qml");

    engine.exec();
}

To run the above example, execute cargo run --example factorial in the project's root directory.

Note regarding the Qt event loop and threads

Creating an Engine automatically initializes the Qt main event loop if one doesn't already exist. At least on some operating systems, the event loop must run on the main thread. Qt will tell you if you mess up. The .exec() method on views starts the event loop. This will block the thread until the window is closed.

Licensing

The code in this library is dual-licensed under the MIT license and the Apache License (version 2.0). See LICENSE-APACHE and LICENSE-MIT for details.

Extension points exported contracts — how you extend this code

ToQVariant (Interface)
(no doc) [5 implementers]
src/variant.rs
Object (Interface)
(no doc)
src/lib.rs
FromQVariant (Interface)
(no doc) [4 implementers]
src/variant.rs

Core symbols most depended-on inside this repo

exec
called by 4
src/lib.rs
load_local_file
called by 3
src/lib.rs
set_property
called by 3
src/lib.rs
qt_metacall
called by 2
ext/libqmlrswrapper/qrsdynamicobject.cpp
get_qobject
called by 1
src/lib.rs
load_url
called by 1
src/lib.rs
load_data
called by 1
src/lib.rs
create
called by 1
ext/libqmlrswrapper/qrsdynamicobject.cpp

Shape

Function 38
Method 28
Class 12
Enum 8
Interface 3

Languages

C++56%
Rust44%

Modules by API surface

ext/libqmlrswrapper/libqmlrswrapper.cpp24 symbols
src/lib.rs19 symbols
ext/libqmlrswrapper/qrsdynamicobject.cpp12 symbols
ext/libqmlrswrapper/qrsdynamicobject_capi.cpp7 symbols
src/ffi.rs6 symbols
src/variant.rs5 symbols
ext/libqmlrswrapper/qrsdynamicobject.h5 symbols
examples/multiply.rs3 symbols
ext/libqmlrswrapper/libqmlrswrapper.h2 symbols
examples/math/mod.rs2 symbols
tests/simple_test.rs1 symbols
examples/factorial_string.rs1 symbols

For agents

$ claude mcp add qmlrs \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page