Skip to main content

QmlModule

Struct QmlModule 

Source
pub struct QmlModule { /* private fields */ }
Expand description

This is a description of a QML module for building by the crate::CxxQtBuilder.

It allows registering QML files that will be included in the QML module. For further resources such as images, these can be added to the Qt resources system via the appropriate CxxQtBuilder functions.

Implementations§

Source§

impl QmlModule

Source

pub fn new(uri: impl Into<QmlUri>) -> Self

Create a new QmlModule with the given URI.

Source

pub fn depend(self, depend: impl Into<QmlUri>) -> Self

Add a QML module dependency

Source

pub fn depends<T: Into<QmlUri>>( self, depends: impl IntoIterator<Item = T>, ) -> Self

Add multiple QML module dependencies

Source

pub fn version(self, version_major: usize, version_minor: usize) -> Self

Add a version to the QML module.

The default version is 1.0.

Source

pub fn plugin_type(self, plugin_type: PluginType) -> Self

Specify the plugin type for the QML module (PluginType::Static by default).

§Limitations of dynamic plugins

Warning: The following limitations apply to building QML modules with PluginType::Dynamic:

§Crate must be built to cdylib

Even though it is possible to build both a staticlib and cdylib from one crate, any crate that uses PluginType::Dynamic for the QML module must build to cdylib. The QML module will not work as expected if built into a staticlib.

§Only One Dynamic Plugin Per Library

There can only be one dynamic QML module plugin per dynamic library. This also applies to sub-crates, so no sub-crate in the dependency tree can build to a dynamic QML module plugin if the main crate is already doing so.

§Final binary should be built with CXX-Qt-CMake

Any binary that loads a dynamic QML module plugin expects a certain file layout of the qmldir and dynamic library files. The easiest way to ensure this is to build the final binary with CXX-Qt-CMake. CXX-Qt does not currently provide any way to generate the required file layout with pure Cargo builds. Prefer building static QML module plugins when building with Cargo only.

§MSVC Runtime Compatibility on Windows

As outlined in the CXX-Qt book, Rust always links to the release runtime under MSVC on Windows. To ensure compatibility when loading dynamic QML module plugins, CXX-Qt will set the QT_NO_DEBUG definition when compiling the C++ code for dynamic QML module plugins under MSVC. This will disable debug features in Qt, even when building a debug build of the Rust crate.

Source

pub fn qml_file(self, file: impl Into<QmlFile>) -> Self

Add a single QML file to the module.

If the Qml file starts is uppercase, it will be treated as a QML component and registered in the qmldir file. See QmlFile for more information on configuring the behavior of QML files.

The crate::CxxQtBuilder will register the file with the Qt Resource System in the default QML import path qrc:/qt/qml/uri/of/module/.

When using Qt 6, the crate::CxxQtBuilder will run qmlcachegen to compile the specified .qml file ahead-of-time.

Additional resources such as images can be added to the Qt resources for the QML module by using the crate::CxxQtBuilder::qrc_resources or crate::CxxQtBuilder::qrc functions.

Note that if no version is specified for the QML file, the version of the QML module will be used automatically.

Source

pub fn qml_files( self, files: impl IntoIterator<Item = impl Into<QmlFile>>, ) -> Self

Add multiple QML files to the module, see Self::qml_file.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.