What pattern to use when setting input variables from another thread? #7329
-
I'm moving all my logic to another thread and keeping the main thread for slint. fn main() -> Result<(), Box<dyn Error>> {
let ui = MainWindow::new().unwrap();
let ui_handle = ui.as_weak();
let ui_handle_sub = ui.as_weak();
ui.on_changed({
move || {
let ui = ui_handle.clone().unwrap(); // OK
...
}
});
std::thread::spawn(move || {
// (this is actually in an msg event loop)
let ui = ui_handle_sub.clone().unwrap(); // Not OK. this is line 136 in the error.
ui.set_status_text( slint::SharedString::from("hi") );
}
});
ui.run()?;
Ok(())
} gives:
|
Beta Was this translation helpful? Give feedback.
Answered by
ultimaweapon
Jan 11, 2025
Replies: 1 comment 1 reply
-
You need to use invoke_from_event_loop. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
gcb
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to use invoke_from_event_loop.