Passing Rust native structs into slint like in Qt #6773
-
In Qt you can define properties of Classes like such: class Data : public QObject {
Q_Property(double DataParameter read getDataParameter write setDataParameter notify DataParameterChanged)
private:
double DataParameter;
public:
double getDataParameter();
void setDataParameter(double);
signals:
DataParameterChanged(double);
} This allows you to register the class as a global in qml and access it without defining anything about the class in your qml file. import Data // this is the C++ class
Text {
text: Data.DataParameter // directly accessing the property through the read definition
} Qt does its magic to allow this binding to be seamless for developers. In Slint: export global SData {
in property <int> Parameter;
} In Rust: struct Data {
Parameter: u16
}
window.global::<SData>().set_Parameter(Data.Parameter.into()); Maybe I'm doing it wrong, but this feels very clunky compared to Qt. Is there a reason we don't have something similar to Qt for this, or has it just not been implemented yet? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
In Slint, the .slint files needs to be self contained and the Slint compiler need to know about every type at compile time. (In QML, it is much more dynamic and we can register type t runtime) We do have plan to be able to import rust structs. This is tracked in #1726 |
Beta Was this translation helpful? Give feedback.
In Slint, the .slint files needs to be self contained and the Slint compiler need to know about every type at compile time. (In QML, it is much more dynamic and we can register type t runtime)
So you can do the opposite by declaring a
export struct Data { ... }
in slint and using that in rust.We do have plan to be able to import rust structs. This is tracked in #1726