From 3232bc30e364ed24aebae01f26e23a3f3b1db9e2 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Mon, 9 Dec 2024 20:37:01 -0500 Subject: [PATCH] cxx-qt-lib: Add binding for QQmlApplicationEngine::loadFromModule This function was added in Qt 6.5, as an alternative from loading files by file path. --- CHANGELOG.md | 1 + crates/cxx-qt-lib/src/qml/qqmlapplicationengine.rs | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01c066438..c15c750f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - QObject subclasses can now inherit from other CXX-Qt generated QObject classes - `BUILD_WASM` CMake option to support WebAssembly builds and a book page for building for WASM - Add support for cxx_name and rust_name on qproperty attributes which applies to the QProperty generated as well as functions +- Add support for loading QML files in `QQmlApplicationEngine` from modules with `loadFromModule`. ### Changed diff --git a/crates/cxx-qt-lib/src/qml/qqmlapplicationengine.rs b/crates/cxx-qt-lib/src/qml/qqmlapplicationengine.rs index 9e7b848a2..967e702b2 100644 --- a/crates/cxx-qt-lib/src/qml/qqmlapplicationengine.rs +++ b/crates/cxx-qt-lib/src/qml/qqmlapplicationengine.rs @@ -12,6 +12,8 @@ mod ffi { type QStringList = crate::QStringList; include!("cxx-qt-lib/qurl.h"); type QUrl = crate::QUrl; + include!("cxx-qt-lib/qanystringview.h"); + type QAnyStringView<'a> = crate::QAnyStringView<'a>; include!("cxx-qt-lib/qqmlapplicationengine.h"); type QQmlApplicationEngine; @@ -36,6 +38,12 @@ mod ffi { /// Loads the root QML file located at url. fn load(self: Pin<&mut QQmlApplicationEngine>, url: &QUrl); + /// Loads the QML type typeName from the module specified by uri. + /// This function was introduced in Qt 6.5. + #[cfg(any(cxxqt_qt_version_at_least_7, cxxqt_qt_version_at_least_6_5))] + #[rust_name = "load_from_module"] + fn loadFromModule(self: Pin<&mut QQmlApplicationEngine>, uri: QAnyStringView, typeName: QAnyStringView); + /// This property holds the directory for storing offline user data #[rust_name = "offline_storage_path"] fn offlineStoragePath(self: &QQmlApplicationEngine) -> QString;