pub struct QmlMethodInvoker { /* private fields */ }Expand description
A thread-safe handle for invoking slots and signals on a QObjectHolder.
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.
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 QObjectHolder::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
impl QmlMethodInvoker
Sourcepub fn new<T>(target: &T) -> QmlMethodInvokerwhere
T: QObjectHolder,
pub fn new<T>(target: &T) -> QmlMethodInvokerwhere
T: QObjectHolder,
Creates a QmlMethodInvoker for target and tracks its lifetime.
Prefer QObjectHolder::get_qml_method_invoker over calling this directly.
Sourcepub fn invoke_method(&self, name: &str) -> bool
pub fn invoke_method(&self, name: &str) -> bool
Schedules name to run on the Qt thread via the Qt event loop.
name must be a qslot or qsignal on the target object.
Returns false if the target has been dropped or name is not found;
returns true otherwise.
Sourcepub fn invoke_method_with_args(
&self,
name: &str,
args: &QList<QVariant>,
) -> bool
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 must be a qslot or qsignal on the target object.
Returns false if the target has been dropped, name is not found,
or the argument types do not match the method signature;
returns true otherwise.