slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
17.7k stars 614 forks source link

Multi-Threaded Nested Model Support #6678

Closed Areopagitics closed 3 weeks ago

Areopagitics commented 1 month ago

I currently have a property in-out property <[{file:File,rows:[Row]}]> all_rows; that works perfectly fine when when I update it using ui.set_all_rows(), but if I make it multi-threaded it returns this error, and this is regardless if I use a Mutex or simply using as_any().downcast_ref.

std::rc::Rc<(dyn Model<Data = slint_generatedAppWindow::Row> + 'static)> cannot be sent between threads safely

Here's the code block using Rust:

ui_handle.upgrade_in_event_loop(move |h|{
                    let model_handle: ModelRc<(File, ModelRc<Row>)> = h.get_all_findings();
                    let model = model_handle.as_any().downcast_ref::<VecModel<(File, ModelRc<Row>)>>().unwrap();
                    model.push(file_rows);
                });

Would this be easy to implement?