slint-ui / slint

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

Can't bring global to Rust scope #5451

Closed RstyDev closed 1 week ago

RstyDev commented 1 week ago

Hi, I'm using Slint with Rust in both RustRover and VSCode, in W10 and I have the same problem. There's no way I can get my global export in scope from Rust. I tried declaring it in a single file, in the main Slint file and in the macro slint::slint!, but had no results. I also tried deleting the export and re-importing in all possible orders but still can't make it work. I can call my global from other slint files, the problem is to call it from Rust. ` slint::include_modules!(); slint::slint!{ export global Logic := { callback pagar(int,int); } } mod db; mod mods;

fn main()->Result<(),slint::PlatformError> { let ui = AppWindow::new()?; let ui_handle = ui.as_weak(); ui.global::(); //<-- here's the problem ui.on_request_increase_value(move || { let ui= ui_handle.unwrap(); ui.set_counter(ui.get_counter() + 1); }); ui.run() }`

Vadoola commented 1 week ago

I'm on mobile so its hard to test, but if I recall you need Turbofish syntax here: ui.global::<Logic>().Pager()

RstyDev commented 1 week ago

I had tried, but it was the same, so I kept trying and it turned out to be that I had changed the directory of the project just copying and pasting the files. Then the compiler stopped adding changes to the target folder. Thanks a lot for your help!