Skip to main content

QmlMethodInvoker

Struct QmlMethodInvoker 

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

A thread-safe handle for invoking slots and signals on a #[qobject] instance.

Calls are scheduled on the Qt event loop and execute on the Qt thread. If the target object has been dropped, calls are silently discarded.

Arguments follow the same coercion rules QML applies when it calls a method: an argument matches a parameter as long as it can be converted to the parameter’s type. These rules apply uniformly, even when a Rust method is invoked from Rust; this path does not enforce Rust’s exact-type semantics, so conversions QML permits (for example between numeric types, or between a number and its textual form) are permitted here too.

When a call executes, Qt borrows the Rc<RefCell<_>> held by the QML engine. If the object is already mutably borrowed on the Qt thread at that moment, the call will panic.

Obtain an instance via QmlObject::get_qml_method_invoker.

§Example

let backend = Backend::default_with_attached_qobject();
let invoker = backend.borrow().get_qml_method_invoker();
std::thread::spawn(move || {
    invoker.invoke_method("dataReady");
}).join().unwrap();

Implementations§

Source§

impl QmlMethodInvoker

Source

pub fn new<T>(target: &T) -> QmlMethodInvoker
where T: QObjectHolder,

Creates a QmlMethodInvoker for target and tracks its lifetime.

Prefer QmlObject::get_qml_method_invoker over calling this directly.

Source

pub fn invoke_method(&self, name: &str) -> bool

Schedules name to run on the Qt thread via the Qt event loop.

name is resolved over the object’s meta-object most-derived-first (QML-added members, then Rust, then the C++ base). Returns false if the target has been dropped or no method named name takes zero arguments; returns true otherwise.

Source

pub fn invoke_method_with_args( &self, name: &str, args: &QList<QVariant>, ) -> bool

Schedules name to run on the Qt thread via the Qt event loop, passing args to the method.

name is resolved over the object’s meta-object most-derived-first (QML-added members, then Rust, then the C++ base), choosing the first candidate whose parameter count matches args and whose arguments are all convertible to the parameter types. Returns false if the target has been dropped, no candidate matches, or a conversion fails; returns true otherwise.

Trait Implementations§

Auto Trait Implementations§

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.