How to receive messages from other thread in GTK?

I’m using GTK-rs and I want to send data(2xu32 and 2xu8 values) from another thread to be drawn in main thread GTK(in ProgressBar).

I’m using two independent modules - Core and GUI, so I can’t just send to Core glib::MainContent::channel sender.

I use crossbeam::channel to connect GUI and Core, but I don’t know how to receive messages in GUI side.
When I would receive this, I will send this info via glib::MainContent but this should I know how to do.

Is there any wa function that will execute once per 0.1 second to check if something is in chanell?

Yes, you will need to use the glib channel, not crossbeam though.

    let (sender, reiceiver) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
    /// ...
    receiver.attach(None, move |action| app.do_action(action));

Attach takes a closure of type T where receiver<T>. Here are the docs for it

And here is an example of porting from a handrolled polled channel to glib channel.

I can’t pass to core module glib channel directly, because I think about different than GTK frontends and this move would block this possibility.

You can use any futures-enabled channel and use it on the GLib main context. Any async runtime-independent Rust future can be spawned on the GLib main context.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.