Skip to main content

QParserStatus

Trait QParserStatus 

Source
pub trait QParserStatus {
    // Provided methods
    fn class_begin(&mut self) { ... }
    fn component_complete(&mut self) { ... }
}
Expand description

A trait for hooking into QML component construction stages.

QParserStatus::class_begin is called first when the object is created, followed by QParserStatus::component_complete once all QML properties have been set. This allows you to defer expensive initialization until the component is fully constructed.

This trait is the Rust equivalent of QQmlParserStatus.

This trait requires the qobject macro with Base = QParserStatus to set up the correct Qt proxy.

§Example

use qtbridge::{QApp, qobject};

#[qobject(Base = QParserStatus)]
pub mod backend {
    use qtbridge::QParserStatus;

    #[derive(Default)]
    pub struct Status {
        somewhat_ready: bool,
    }

    impl Status {
        #[qsignal]
        fn ready(&mut self);
    }

    impl QParserStatus for Status {
        fn class_begin(&mut self) {
            self.somewhat_ready = true;
        }

        fn component_complete(&mut self) {
            if self.somewhat_ready {
                self.ready();
            }
        }
    }
}

const QML_CODE: &str =
r#"
    import QtQuick
    import QtQuick.Controls
    // import your module

    ApplicationWindow {
        visible: true
        Status {
            onReady: closeTimer.start()
        }
        Timer {
            id: closeTimer
            interval: 1
            onTriggered: Qt.quit()
        }
    }
"#;

fn main() {
    QApp::new()
        .register::<backend::Status>()
        .load_qml(QML_CODE.as_bytes())
        .run();
}

Provided Methods§

Source

fn class_begin(&mut self)

Called when the object is first created, before any properties are set.

Use this to perform any initialization that must happen before properties are applied.

Source

fn component_complete(&mut self)

Called after all QML properties have been set.

Use this to perform initialization that depends on property values, or to emit signals that notify QML the object is ready.

Implementors§