You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My program has a worker thread that the UI needs to interact with. I'm presently using queued_callback to do this, which in itself is fine. But in order to actually affect any UI changes in its callback, you need to do some acrobatics that feel very unsettling to a Rust developer.
This is the pattern I arrived at, and the only thing I could get to work:
This is very hairy, and I'm not even certain it's correct. (If self_ptr wasn't pinned before, does that mean it could be moved before the callback triggers?) If this is indeed the intended pattern, it would be great to facilitate it, perhaps via a version that does the capturing for you, something like this:
traitCallbackHelper{fncapturing_queued_callback<T:Send>(&mutself,func:fn(&mutSelf,T),) -> Box<dynFn(T) + Send + Sync>;}impl<Q:QObject>CallbackHelperforQ{fncapturing_queued_callback<T:Send>(&mutself,func:fn(&mutSelf,T),) -> Box<dynFn(T) + Send + Sync>{// Rust does not believe I should be able to implement this}}
The text was updated successfully, but these errors were encountered:
mullr
changed the title
A safer-feeling way to get interact with other threads would be very nice
A safer way to get interact with other threads would be very nice
Feb 7, 2022
I understand now that 'self' is in fact pinned, as long as it has previously been handed over to qmetaobject-rs. I think a more idiomatic way to deal with this in client code would be to require do_stuff_in_a_qobj to take a Pin<Box<Self>> or similar as its self type (I /think/ you can do that now).
My program has a worker thread that the UI needs to interact with. I'm presently using
queued_callback
to do this, which in itself is fine. But in order to actually affect any UI changes in its callback, you need to do some acrobatics that feel very unsettling to a Rust developer.This is the pattern I arrived at, and the only thing I could get to work:
This is very hairy, and I'm not even certain it's correct. (If self_ptr wasn't pinned before, does that mean it could be moved before the callback triggers?) If this is indeed the intended pattern, it would be great to facilitate it, perhaps via a version that does the capturing for you, something like this:
The text was updated successfully, but these errors were encountered: