pub trait QObjectHolder:
DispatchMetaCall
+ QMetaInfo
+ Default {
// Provided methods
fn get_qml_method_invoker(&self) -> QmlMethodInvoker { ... }
fn default_with_attached_qobject() -> Rc<RefCell<Self>> { ... }
fn attach_qobject(instance: &Rc<RefCell<Self>>) { ... }
fn detach_qobject(&self) { ... }
fn as_qvariant(&self) -> QVariant { ... }
}Expand description
Provides access to the underlying QObject for types exposed to QML.
Automatically implemented by qobject. Do not implement this trait manually.
Provided Methods§
Sourcefn get_qml_method_invoker(&self) -> QmlMethodInvoker
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");Sourcefn default_with_attached_qobject() -> Rc<RefCell<Self>>
fn default_with_attached_qobject() -> Rc<RefCell<Self>>
Creates a default-initialized instance and attaches the required
[QObject], enabling its use in QML.
The returned Rc<RefCell<Self>> owns the object. The QML side can access it only through
a weak pointer.
The drop implementation of Self calls detach_qobject and thus destroys the associated
QObject, which removes it from the QML side as well. If Self has a custom Drop
implementation, you need to call Self::detach_qobject manually.
The attached QObject is bound to this specific allocation, so the object’s identity and
lifetime must both be preserved.
Do not move or replace the Self inside the Rc<RefCell<Self>>.
Operations such as Rc::try_unwrap, into_inner, or get_mut-then-move will break the
connection between self and the associated QObject. Once the Self lives
elsewhere, the next call in either direction can no longer reach it.
Sourcefn attach_qobject(instance: &Rc<RefCell<Self>>)
fn attach_qobject(instance: &Rc<RefCell<Self>>)
Attaches a dedicated [QObject] to an existing instance,
enabling its use in QML.
Sourcefn detach_qobject(&self)
fn detach_qobject(&self)
Detaches and removes the dedicated [QObject] from this instance.
Called automatically by the Drop implementation generated by the
qobject macro.
Sourcefn as_qvariant(&self) -> QVariant
fn as_qvariant(&self) -> QVariant
Returns a QVariant containing a pointer to this object.
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.