QML (Qt Quick) bindings for Rust language

Related tags

GUI rust gui qt qml
Overview

QML-rust - bindings for Qt Quick

Build Status Crates.io

Bindings are based on DOtherSide C bindings for QML Library is mostly feature-compliant with other bindings based on the library, but lacks some minor features and has quite a few bugs.

documentation

Examples

All examples are located in a folder examples/, under example_name.rs and example_name.qml names.

  • cargo run --example properties for setting properties from Rust to QML.
  • cargo run --example listmodel for an example of providing QML with list model from Rust.
  • cargo run --example listmodel_macro for the same example, but using Q_LISTMODEL! and Q_LISTMODEL_ITEM! macro.
  • cargo run --example sigslots for an example of how to create your own QObject with signals and slots, and to communicate between QML and Rust. Also shows how to use Q_OBJECT! macro.
  • cargo run --example qobjects for an example of how to use Q_OBJECT! macro with different types.
  • cargo run --example qvarlists for an example of how to use qvarlist! macro to easily form QVariant (used to pass data to QML) of a complex array.
  • cargo run --example threaded for an example of multithreading.
  • cargo run --example qmlregister for an example of how to register and use your own types from Rust in QML.
  • An example in examples/resources (should be run manually by cargo run) shows how to use qrc resources.

Requires CMake, Make, Qt (Core, Gui, Widgets, Quick), pkg-config (only for OS X and GNU/Linux) and, of course, Rust.

To run tests: RUST_TEST_THREADS=1 cargo test

In-app examples

  • Architect - an app showing some git stats, using qml-rust to provide properties and lists to QML in here.
  • Kefia - A simple package manager, that provides a QListModel to QML, registers a QObject with slots and communicates between QML and Rust, here.

Status

Done:

  • Basic initialization and execution.
  • Providing properties to QML files.
  • QAbstractListModels - provides changable models for QML items (early draft, still lacks proper mutability).
  • QObjects: slots, signals (limited properties support). Emitting signals and receiving slots works.
  • Registering your own QML types (singletons or not) from Rust code.

To be done:

  • the library is mostly done, but some stuff is lacking polish, like possible memory leaks or better macro designs.
Comments
  • Adjust build_lib.sh for Windows

    Adjust build_lib.sh for Windows

    I propose to adjust the current build script as it is not usable on Windows systems due to two reasons:

    1. Windows does not natively run .sh scripts unless one has installed the shell via cygwin or activated the linux-shell on Windows 10's developer mode. Still, we could add a batch script to make life easier.

    2. cmake defaults to the MSVCC generator on Windows and calling make consequently results in an error since no make files have been generated. We could either explicitly call cmake -G "Unix Makefiles" .. or run MSVCC's compiler. I haven't tried the latter yet but generating Unix Makefiles works fine on my system with Windows 10. Again, avoiding cygwin and the like would make life a lot easier, though. ;)

    enhancement help wanted 
    opened by leviat 18
  • Changing engine properties inside slots

    Changing engine properties inside slots

    I'm looking into replacing qmlrs with qml-rust in one of my projects. The backend of the application exposes its data using a bunch of QListModel instances to the fontend written in QML. When to user kicks off an action the QML side calls a slot of a singleton object. The slot handler code on the Rust side will do his thing and then update some of the QListModel instances and return. My problem is that I can't figure out how to get a hold of a reference to the QListModels. I tried to make them properties of the singleton which failed, I also had the idea to put the QmlEngine instance into a global static RwLock. Any ideas?

    question 
    opened by flanfly 5
  • impl QMetaTypable for f64 is missing

    impl QMetaTypable for f64 is missing

    According to the doc, only String and i32 implement QMetaTypable. This means one can't pass a floating point value from/to QML.

    Could an impl be added for either f32 or f64?

    Thanks!

    opened by nbigaouette 5
  • Make the build script support Windows and BSD

    Make the build script support Windows and BSD

    This extends the build script to use the cmake crate to build the native extension. On Windows it will be build with MSVC. The PR also gets rid of the build_lib.sh and adds DOtherSide as git submodule.

    opened by flanfly 4
  • Allow loading from resource

    Allow loading from resource

    opened by nbigaouette 4
  • Use QGuiApplication, not QApplication, in qmlengine.rs

    Use QGuiApplication, not QApplication, in qmlengine.rs

    QtQuick requires a QGuiApplication. QApplication derives from QGuiApplication, so it can do the job, but it creates an unnecessary dependency on QtWidgets, which is undesirable for a QtQuick-only application.

    enhancement 
    opened by Thra11 3
  • Replace explicit i8 with libc::c_char, to allow it to compile on ARM.

    Replace explicit i8 with libc::c_char, to allow it to compile on ARM.

    Despite the docs saying that libc::c_char is equivalent to i8, it would appear that libc::c_char actually follows the idiosyncracies of the C char type that it represents. That is, on some platforms it is equivalent to signed char (i8) and on others it is unsigned char (u8). By explicitly using libc::c_char in the stoptr and ptrtos functions, we avoid mismatched type errors when compiling on ARM.

    opened by Thra11 3
  • Enum registering?

    Enum registering?

    I tried to find how to register enums, but couldn't see any indication of support for such in the examples nor the code. Is there a preferred workaround for this?

    opened by bzar 3
  • enahnce Q_LISTMODEL to support struct insert

    enahnce Q_LISTMODEL to support struct insert

    I don’t know if it is a desired feature but I think it is much more handy to insert structs then to insert structs fields to a QListModel.

    I wrote a macro that wraps the old behaviour: https://github.com/berlineddy/qml-rust/commit/462004f84a0f870e3f30fbfe6aeeaa7eef145898

    proposed syntax:

    Q_LISTMODEL_ITEM!{
        pub TestModel<TestModelItem> {
            name: String,
            number: i32,
        }
    }
    
    // ...
    
    let mut qqae = QmlEngine::new();
    let mut qalm = QTestModel::new();
    let item1 = TestModelItem {
        name: "foo".into(),
        number: 42
    };
    let item2 = TestModelItem {
        name: "bar".into(),
        number: 23
    };
    qalm.insert_item(item1);
    qalm.insert_item(item2);
    // `&QTestModel` implements `Into<QVariant>`
    qqae.set_and_store_property("listModel", &qalm);
    qqae.exec();
    

    If this feature is wanted I'll do a push request otherwise this issue can be closed.

    enhancement 
    opened by fneddy 3
  • add support for Q_LISTMODEL with only one member

    add support for Q_LISTMODEL with only one member

    currently it is not possible to create a Q_LISTMODEL! with only one member:

    Q_LISTMODEL!{
        pub QTestModel {
            name: String,
        }
    }
    
    error: expected one of `,` or `@`, found `)`
      --> <qml macros>:22:26
       |
    22 | | ( $ ( $ rolename ) , * ) | {
       |                          ^
    
    error: expected pattern, found `{`
      --> <qml macros>:22:30
       |
    22 | | ( $ ( $ rolename ) , * ) | {
       |                              ^
    
    error: expected expression, found statement (`let`)
      --> <qml macros>:23:1
       |
    23 | let mut vec = Vec :: new (  ) ; $ ( vec . push ( $ rolename . into (  ) ) ; )
       | ^^^
       |
       = note: variable declaration using `let` is a statement
    
    error: expected one of `,`, `->`, `.`, `<`, `?`, `break`, `continue`, `for`, `if`, `loop`, `match`, `move`, `return`, `unsafe`, `while`, or an operator, found `let`
      --> <qml macros>:23:1
       |
    23 | let mut vec = Vec :: new (  ) ; $ ( vec . push ( $ rolename . into (  ) ) ; )
       | ^^^
    
    error: expected one of `->`, `.`, `;`, `<`, `?`, `break`, `continue`, `for`, `if`, `loop`, `match`, `move`, `return`, `unsafe`, `while`, `}`, or an operator, found `let`
      --> <qml macros>:23:1
       |
    23 | let mut vec = Vec :: new (  ) ; $ ( vec . push ( $ rolename . into (  ) ) ; )
       | ^^^
    
    error: expected one of `const`, `default`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `)`
      --> <qml macros>:24:9
       |
    24 | * vec } ) . collect :: < Vec < Vec < QVariant >> > (  ) ) }
       |         ^
    
    error: Could not compile `z-machine`.
    
    To learn more, run the command again with --verbose.
    
    bug 
    opened by fneddy 3
  • Array as parameter of signal

    Array as parameter of signal

    Is it possible to have an array as parameter of a signal? I want to pass Vec but this declaration fails:

    Q_OBJECT! {
        pub Logic as QLogic {
        signals:
            fn gains(gainList: QVariant);
    

    with error:

    src/main.rs:45:36: 76:54 error: no associated item named `metatype` found for type `qml::qvariant::QVariant` in the current scope
    (internal compiler error: unprintable span)
    src/main.rs:41:1: 50:2 note: in this expansion of Q_OBJECT! (defined in <qml macros>)
    

    Which types can be signal parameters?

    bug 
    opened by vchekan 3
  • Project state

    Project state

    Hi!

    What is the current project state? Was it discontinued? Why so? This looks pretty great whilst the qt rust bindings generator really doesn't.

    Thanks for any answers! Best, Yatekii

    opened by Yatekii 1
  • unresolved external symbols on Windows 8.1

    unresolved external symbols on Windows 8.1

    Trying to build this with the latest nightly:

       Compiling sousa v0.1.0 (file:///D:/projects/sousa)
    error: linking with `link.exe` failed: exit code: 1120
    note: "D:\\Program Files\\Microsoft Visual Studio 14.0\\VC\\bin\\amd64\\link.exe" "/NOLOGO" "/NXCOMPAT" "/LIBPATH:D:\\Program Files\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "D:\\projects\\sousa\\target\\debug\\deps\\sousa-cc9d6e6379baec73.0.o" "/OUT:D:\\projects\\sousa\\target\\debug\\deps\\sousa-cc9d6e6379baec73.exe" "D:\\projects\\sousa\\target\\debug\\deps\\sousa-cc9d6e6379baec73.crate.allocator.o" "/OPT:REF,NOICF" "/DEBUG" "/NATVIS:D:\\Program Files\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:D:\\Program Files\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis" "/LIBPATH:D:\\projects\\sousa\\target\\debug\\deps" "/LIBPATH:C:\\Windows\\system32" "/LIBPATH:D:\\data\\Qt\\Qt5.8.0\\5.8\\msvc2015_64\\lib" "/LIBPATH:D:\\projects\\sousa\\target\\debug\\build\\qml-b3da3924b4fd8479\\out\\lib" "/LIBPATH:D:\\projects\\sousa\\target\\debug\\build\\qml-b3da3924b4fd8479\\out\\build\\lib\\Release" "/LIBPATH:D:\\Program Files\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "D:\\projects\\sousa\\target\\debug\\deps\\libqml-8b7edbfc429f2223.rlib" "D:\\projects\\sousa\\target\\debug\\deps\\liblazy_static-cb739ed98755003d.rlib" "D:\\projects\\sousa\\target\\debug\\deps\\liblibc-d147521939f78f0c.rlib" "D:\\Program Files\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-dca4b73029f3479e.rlib" "D:\\Program Files\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-e1674c3de8a486d7.rlib" "D:\\Program Files\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-795d569cacd9eec9.rlib" "D:\\Program Files\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-ff2b57c12e14fd49.rlib" "D:\\Program Files\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc_system-6108368a26c0af1c.rlib" "D:\\Program Files\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-8293dc8c9ac9fe00.rlib" "D:\\Program Files\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd_unicode-75578c31b1e15ba3.rlib" "D:\\Program Files\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librand-122e151e5c31e37b.rlib" "D:\\Program Files\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-08a2018b8fb6bf88.rlib" "D:\\Program Files\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-3d953567610cee9c.rlib" "Qt5Core.lib" "Qt5Gui.lib" "Qt5Qml.lib" "Qt5Quick.lib" "Qt5Svg.lib" "Qt5Widgets.lib" "DOtherSide.lib" "advapi32.lib" "ws2_32.lib" "userenv.lib" "shell32.lib" "msvcrt.lib"
    note: libqml-8b7edbfc429f2223.rlib(qml-8b7edbfc429f2223.0.o) : error LNK2019: unresolved external symbol dos_qabstractlistmodel_beginRemoveRows referenced in function _ZN3qml17qabstactlistmodel10QListModel10remove_row17h5aee948953d5d8d4E
    
    libqml-8b7edbfc429f2223.rlib(qml-8b7edbfc429f2223.0.o) : error LNK2019: unresolved external symbol dos_qabstractlistmodel_endRemoveRows referenced in function _ZN3qml17qabstactlistmodel10QListModel10remove_row17h5aee948953d5d8d4E
    
    libqml-8b7edbfc429f2223.rlib(qml-8b7edbfc429f2223.0.o) : error LNK2019: unresolved external symbol dos_qabstractlistmodel_beginResetModel referenced in function _ZN3qml17qabstactlistmodel10QListModel8set_data17hbd67b04ee140cd24E
    
    libqml-8b7edbfc429f2223.rlib(qml-8b7edbfc429f2223.0.o) : error LNK2019: unresolved external symbol dos_qabstractlistmodel_endResetModel referenced in function _ZN3qml17qabstactlistmodel10QListModel8set_data17hbd67b04ee140cd24E
    
    D:\projects\poc\sousa\target\debug\deps\sousa-cc9d6e6379baec73.exe : fatal error LNK1120: 4 unresolved externals
    
    
    error: Could not compile `sousa`.
    
    Caused by:
      process didn't exit successfully: `rustc --crate-name sousa src\main.rs --error-format json --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=cc9d6e6379baec73 -C extra-filename=-cc9d6e6379baec73 --out-dir D:\projects\poc\sousa\target\debug\deps -L dependency=D:\projects\poc\sousa\target\debug\deps --extern qml=D:\projects\poc\sousa\target\debug\deps\libqml-8b7edbfc429f2223.rlib -L native=C:\Windows\system32 -L native=D:\data\Qt\Qt5.8.0\5.8\msvc2015_64\lib -L native=D:\projects\poc\sousa\target\debug\build\qml-b3da3924b4fd8479\out\lib -L native=D:\projects\poc\sousa\target\debug\build\qml-b3da3924b4fd8479\out\build\lib\Release` (exit code: 101)
    
    opened by Boscop 0
  • Add ability to load different properties for on page chage

    Add ability to load different properties for on page chage

    I'm designing a multi-page/window GUI. To clean up my code, I'd like to pass properties from different files on page change.

    For example:

    1. You start the app and main.rs calls upon main.qml.
    2. You click the button Show Users.
    3. users.qml is loaded with variables provided by users.rs.

    etc. I want to create a 1:1 mapping of views and "controllers".

    I'd love to see this ability in the future! I'm completely new to Rust and Qt Quick, so if this isn't part of the spec just let me know.

    opened by kieraneglin 0
  • Memory corruption

    Memory corruption

    My application started exiting with status code 1 and I think one time I've seen signal 11 too. Investigation narrowed it down to this line:

     let mut local = $wrapper{
        origin: Box::new(origin),
        ptr: ::std::mem::uninitialized(),
    

    I've replaced uninitialized() with zeroed() and my app is working again: https://github.com/vchekan/qml-rust/commit/21f25e63fab0f5cde73f6d95a66a56c7150e53f7

    I do not understand qml low level api and I am not sure what is going on with pointer manipulations in $wrapper::with_no_props() and QmlObject::new() so i do not consider it a proper fix, so if somebody has insight, please share.

    opened by vchekan 0
  • Build fails on rust-1.17

    Build fails on rust-1.17

    I am not 100% sure it is the cause, but roughly after updating from 1.16 to 1.17 I can my project fails and qmp-rust unit tests do not pass either:

    $ ~/projects/qml-rust/src $ cargo test
       Compiling lazy_static v0.2.8
       Compiling libc v0.2.22
       Compiling gcc v0.3.45
       Compiling pkg-config v0.3.9
       Compiling cmake v0.1.22
       Compiling qml v0.0.9 (file:///home/vadim/projects/qml-rust)
        Finished dev [unoptimized + debuginfo] target(s) in 23.13 secs
         Running /home/vadim/projects/qml-rust/target/debug/deps/qml-9c345ca780cadf43
    
    running 5 tests
    WARNING: QApplication was not created in the main() thread.
    WARNING: QApplication was not created in the main() thread.
    error: process didn't exit successfully: `/home/vadim/projects/qml-rust/target/debug/deps/qml-9c345ca780cadf43` (signal: 11, SIGSEGV: invalid memory reference)
    
    To learn more, run the command again with --verbose.
    

    Linux Mint 18.1 Serena

    rustc 1.17.0 (56124baa9 2017-04-24)

    opened by vchekan 1
Owner
Oak
Oak
Rust bindings to Core Foundation and other low level libraries on Mac OS X and iOS

core-foundation-rs Compatibility Targets macOS 10.7 by default. To enable features added in macOS 10.8, set Cargo feature mac_os_10_8_features. To hav

Servo 685 Jan 2, 2023
Rust bindings for the FLTK GUI library.

fltk-rs Rust bindings for the FLTK Graphical User Interface library. The FLTK crate is a crossplatform lightweight gui library which can be statically

Mohammed Alyousef 1.1k Jan 9, 2023
Rust bindings for Dear ImGui

imgui-rs: Rust bindings for Dear ImGui (Recently under new maintenance, things subject to change) Window::new(im_str!("Hello world")) .size([300.0

null 2k Jan 7, 2023
Rust bindings to the minimalist, native, cross-platform UI toolkit `libui`

Improved User Interface A cross-platform UI toolkit for Rust based on libui iui: ui-sys: iui is a simple (about 4 kLOC of Rust), small (about 800kb, i

Rust Native UI Group 865 Dec 27, 2022
Rust bindings for Sciter

Rust bindings for Sciter Check this page for other language bindings (Delphi / D / Go / .NET / Python / Rust). Introduction Sciter is an embeddable mu

Terra Informatica Software, Inc 757 Dec 30, 2022
Provides Rust bindings for GTK libraries

The gtk-rs organization aims to provide safe Rust binding over GObject-based libraries

null 431 Dec 30, 2022
Provides Rust bindings for Gnome libraries

gtk-rs-core The gtk-rs organization aims to provide safe Rust binding over GObject-based libraries. You can find more about it on https://gtk-rs.org.

null 174 Dec 26, 2022
Drew's fast Rust AppKit bindings

Drew's fast Rust AppKit bindings Provides select Rust bindings for Apple AppKit framework. This may be compared to, appkit crate cacao objrs_framework

Drew Crawford 2 Oct 28, 2022
Rust bindings for Dear ImGui

imgui-rs: Rust bindings for Dear ImGui (Recently under new maintenance, things subject to change) ui.window("Hello world") .size([300.0, 100.0], C

null 2k Jan 7, 2023
Rust bindings and wrappers for GLib, GDK 3, GTK+ 3 and Cairo.

THIS REPOSITORY IS DEPRECATED SEE: https://github.com/rust-gnome rgtk Rust bindings and wrappers for GLib, GDK 3, GTK+ 3 and Cairo. Building rgtk expe

Jeremy Letang 124 Jul 10, 2022
Provides Rust bindings for GTK libraries

gtk3-rs The gtk-rs organization aims to provide safe Rust binding over GObject-based libraries. You can find more about it on https://gtk-rs.org. This

null 431 Dec 30, 2022
Rust bindings for the FLTK GUI library.

fltk-rs Rust bindings for the FLTK Graphical User Interface library. The fltk crate is a cross-platform lightweight gui library which can be staticall

fltk-rs 1.1k Jan 9, 2023
The bindings to the Nuklear 2D immediate GUI library.

nuklear-rust The bindings to the Nuklear 2D immediate GUI library. Currently beta. Drawing backends: gfx-pre-ll for GFX 3D drawing engine (examples: O

Serhii Plyhun 332 Dec 27, 2022
Egui bindings for macroquad

egui bindings for macroquad This is the easiest way to use egui. Just two functions! Web demo. Usage You need to call ui when you need to get informat

ilya sheprut 54 Dec 28, 2022
Egui bindings for miniquad

egui bindings for miniquad native On Linux you first must run apt install libx11-dev libxi-dev libgl1-mesa-dev (miniquad dependencies). cargo run --re

Fedor Logachev 48 Dec 28, 2022
Unsafe bindings and a safe wrapper for gtk4-layer-shell, automatically generated from a .gir file

gtk4-layer-shell: gtk4-layer-shell-sys: gtk4-layer-shell This is the safe wrapper for gtk4-layer-shell, automatically generated from its .gir file. Fo

null 3 Apr 30, 2023
Qt5 binding for rust language. (stalled)

Qt5 binding for Rust language. qt.rs This project provides bindings that allow the QT Gui toolkit to be used from the Rust Programming language. Compi

yatsen1 37 Oct 12, 2021
Windows Native Undocumented API for Rust Language 🔥

Windows Native   The Windows-Native Rust library provides a convenient and safe way to access the native Windows undocumented APIs using the Rust prog

null 3 Aug 22, 2023
An easy to use command line project manager for projects using the ReCT programming language

☢️ A powerful project manager for the ReCT programming language! ☢️ ReCTx makes your projects easier to manage by allowing you to configure everything

Remy 1 Nov 28, 2022