Skip to main content

QmlObject

Trait QmlObject 

Source
pub trait QmlObject: QObjectHolder {
    // Provided methods
    fn default_with_attached_qobject() -> Rc<RefCell<Self>>
       where Self: Default { ... }
    fn attach_qobject(instance: &Rc<RefCell<Self>>) { ... }
    fn detach_qobject(&self) { ... }
    fn get_qml_method_invoker(&self) -> QmlMethodInvoker { ... }
}

Provided Methods§

Source

fn default_with_attached_qobject() -> Rc<RefCell<Self>>
where Self: Default,

Creates a default-initialized instance and attaches its [QObject] eagerly.

The returned Rc<RefCell<Self>> is an ordinary handle, shared with QML. Droping the handle does not drop the instance if it is in use by QML or until the garbage collection delete the QML instance.

Source

fn attach_qobject(instance: &Rc<RefCell<Self>>)

Attaches a dedicated [QObject] to an existing instance, enabling its use in QML.

Source

fn detach_qobject(&self)

Detaches and deletes the dedicated [QObject] of this instance.

The instance continues as a plain Rust value and heals with a fresh [QObject] on its next exposure to QML.

Source

fn get_qml_method_invoker(&self) -> QmlMethodInvoker

Returns a QmlMethodInvoker that can invoke methods on the underlying QObject from any thread.

§Example
let backend = Backend::default_with_attached_qobject();
let invoker = backend.borrow().get_qml_method_invoker();
invoker.invoke_method("dataReady");

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T: QObjectHolder> QmlObject for T