White-Oak / qml-rust

QML (Qt Quick) bindings for Rust language
MIT License
205 stars 18 forks source link

Connect to a signal in Rust #26

Closed flanfly closed 7 years ago

flanfly commented 7 years ago

Hey, I have a QObject with a bunch of properties exposed to QML. Now, when the QML side writes one of the properties I want a Rust function to be called. So, how do I do something like sig.connect(|| { ... }) in Rust?

White-Oak commented 7 years ago

@flanfly I usually do it from the other way around: I connect Rust signals in QML: https://github.com/White-Oak/kefia/blob/master/src/view.qml#L185-L190. In this case you want to connect a signal of Rust's QObject to a slot of Rust QObject:

        Component.onCompleted: {
          rustQobj.some_prop_changed.connect(rustQobj.some_other_slot)
        }
flanfly commented 7 years ago

Thanks for the fast answer @White-Oak. I guess the meta answer is that connecting to signals in Rust is not possible :smile:. I'll keep using separate slots to write properties in case I need to be notified.