Skip to main content

QApp

Struct QApp 

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

Entry point for a Qt QML application.

Wraps the Qt application and QML engine. Configure it with the builder methods and call run to start the event loop.

§Example

A minimal “Hello World” application without a Rust backend:

QApp::new()
    .load_qml(br#"
        import QtQuick
        import QtQuick.Controls
        Text {
            text: "Hello Rust!"
        }"#)
    .run();

Implementations§

Source§

impl QApp

Source

pub fn new() -> QApp

Creates the Qt application and QML engine.

Must be called before any QML or GUI functionality is used.

Source

pub fn run(&mut self) -> i32

Enters the Qt main event loop.

Blocks until the application exits and returns the exit code. Usually the last call in main.

Source

pub fn add_initial_property(&mut self, id: &str, value: &QVariant) -> &mut QApp

Queues an initial property to be set on the root QML object.

Properties are applied when load_qml or load_qml_from_file is called. Call multiple times to set several properties.

§Example
let prop = 42;

QApp::new()
.add_initial_property("answer", &prop.into())
.load_qml(br#"
    import QtQuick
    import QtQuick.Controls
    ApplicationWindow {
        required property var answer
    }"#)
.run();
Source

pub fn with_initial_properties( &mut self, properties: &[(&str, QVariant)], ) -> &mut QApp

Sets multiple initial properties on the root QML object at once.

Must be called before load_qml or load_qml_from_file.

§Example
let prop = 42;

QApp::new()
    .with_initial_properties(&[
        ("answer", prop.into()),
    ])
    .load_qml(br#"
        import QtQuick
        import QtQuick.Controls
        ApplicationWindow {
            required property var answer
        }"#)
    .run();
Source

pub fn load_qml(&mut self, code: &[u8]) -> &mut QApp

Loads QML source from an in-memory byte slice.

Applies any properties queued with add_initial_property before loading.

Source

pub fn load_qml_from_file(&mut self, url: &str) -> &mut QApp

Loads the entry-point QML file by URL.

Use this instead of load_qml when the QML is embedded in a Qt resource (qrc:) or accessible as a file path. Accepts URLs such as "qrc:/qt/qml/MyApp/Main.qml" or "file:///path/to/main.qml".

Import paths for any modules the file uses must be registered with add_import_path before this call.

Source

pub fn add_import_path(&mut self, path: &str) -> &mut QApp

Adds a directory to the QML engine’s module import search path.

Call before load_qml_from_file when the loaded QML imports modules from a directory the engine would not otherwise find. Accepts both URLs and file-system paths.

Source

pub fn register<T>(&mut self) -> &mut QApp
where T: QmlRegister,

Registers T with the QML type system, making it instantiable from QML.

#[derive(Default)]
pub struct Backend {
}
#[qobject]
impl Backend {
}

QApp::new()
    .register::<Backend>()
    .load_qml(br#"
        import QtQuick
        import QtQuick.Controls
        ApplicationWindow {
            Backend {}
     }"#)
    .run();
Source

pub fn application_name(&mut self, name: &str) -> &mut QApp

Sets the application name reported to the OS.

Auto Trait Implementations§

§

impl Freeze for QApp

§

impl RefUnwindSafe for QApp

§

impl !Send for QApp

§

impl !Sync for QApp

§

impl Unpin for QApp

§

impl UnsafeUnpin for QApp

§

impl UnwindSafe for QApp

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.