Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cxx-qt-lib: Add binding for QQmlApplicationEngine::loadFromModule #1141

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 16 additions & 0 deletions crates/cxx-qt-lib/src/qml/qqmlapplicationengine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

#[cxx::bridge]
mod ffi {
unsafe extern "C++" {
#[cfg(any(cxxqt_qt_version_at_least_7, cxxqt_qt_version_at_least_6_5))]
include!("cxx-qt-lib/qanystringview.h");
type QAnyStringView<'a> = crate::QAnyStringView<'a>;
}

unsafe extern "C++" {
include!("cxx-qt-lib/qstring.h");
type QString = crate::QString;
Expand Down Expand Up @@ -36,6 +42,16 @@ 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;
Expand Down
Loading