Skip to content

Conversation

bennysj
Copy link
Contributor

@bennysj bennysj commented Sep 16, 2025

The idea to make it easier and more convenient to pass a reference to a Slint global instance into a Rust closure / lambda.

The current implementation works the following way:

  pub fn init(blogica_api: &BLogicAAPI) {
        blogica_api.on_update_data({
            let blogica_api_weak = blogica_api.as_weak();
            |bdata| {
                let blogica_api = blogica_api_weak.upgrade().unwrap();
                // It would have been very nice if the call to .global() could avoided, as it depends on the lifetime
                // of the GlobalStrong<T> it's needed
                let blogica_api = blogica_api_weak.to_global();

                // Do stuff here with blogica_api
            }
        });
    }

Fixes #9389

@bennysj bennysj force-pushed the global_comp_improvments branch 3 times, most recently from 7a0c646 to ab2a50a Compare September 16, 2025 14:04
The idea to make it easier and more convenient to pass a reference
to a Slint global instance into a Rust closure / lambda.

Fixes slint-ui#9389
@bennysj bennysj force-pushed the global_comp_improvments branch from ab2a50a to 595f2e2 Compare September 16, 2025 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement .as_weak() and .upgrade() for global component instances
1 participant