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_thread_handle(&self) -> QThreadHandle<Self> { ... }
}

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_thread_handle(&self) -> QThreadHandle<Self>

Returns a QThreadHandle that can schedule Rust closures to run on this object on the Qt thread, from any thread.

This function can only be called on the Qt thread for QmlObject that live in this thread.

§Example
let backend = Backend::default_with_attached_qobject();
let handle = backend.borrow().get_thread_handle();
handle.invoke_mut(|b| b.value = 42);

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