Replies: 2 comments
-
You shouldn't move the strong reference to the callback as that will cause leak (cycle in the refcount) So move the (cloned) weak to the callback (also in on_choose_video_file) and move it again (cloned) in the thread, ui.on_compress_video({
let ui_handle = ui_handle.clone(); // clone the weak to move it to the callback
move || {
let (tx, rx) = std::sync::mpsc::channel::<f32>();
// can unwrap in the callback, that's fine
let input = ui_handle.unwrap().get_compress_video_input_file_path().clone();
let input = std::path::Path::new(input.as_str());
let video_type = "mp4";
compress_video(input, video_type, tx);
let ui_handle = ui_handle.clone(); // clone it again to move it to the thread
thread::spawn(move || {
while let Ok(progress) = rx.recv() {
// use upgrade_in_event_loop to get a callback in the main thread again.
ui_handle.upgrade_in_event_loop(move |ui| ui.set_compressing_progress_value(progress));
println!("{}", progress);
}
});
}
}); I hope this helps. |
Beta Was this translation helpful? Give feedback.
0 replies
-
The slint staff is very quick to respond and the solutions are very effective, I hope slint grows from strength to strength! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to make a progress bar for my program and I need to put the task of updating the progress bar in a subthread, but I can't pass the ui into the subthread, is this the right way for me to implement my idea? Or is there a more standard way of doing it?
Beta Was this translation helpful? Give feedback.
All reactions