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
Hi,
I'm a new qmetaobject-rs user, and I'm trying to use QEnum-deriving enum as a property type. My code compiles, but at runtime qml sees the property type Object instead of int. Any hints are welcome. The minimal (broken) example and output are below.
Thanks for sharing your code; it helped me progress on a similar enum vs. int related typing issue while trying to set an enum property. When I try to set my property with "my_property = MyEnum.MyVariant" in a callback, I hit ":57: Error: Cannot assign int to TypeId{t:11890792827600742819}"
You ~did declare "property int testprop"... did you already try "property var testprop" or "property backend.OpMode"?
I believe this has to do with enums in C not being types; they're "tags" and have type int. So the type of the enum is conflated with the type of the variant, and enums aren't really first class types. I am still looking for a workaround, but the answer might just be to give up on enums in qt and resort to stringly or intly typed code.
I changed my property that was previously my enum to be an i32: stateMachineQt: qt_property!(i32; READ getState WRITE setState NOTIFY state_changed),
Then I implemented TryFrom for it following:
This alone wouldn't provide much type safety, since I could still use the wrong enum in the QML, but I mitigated it using large random numbers for my enum variants so they ~probably won't collide with the variants of any other enums:
Hi,
I'm a new
qmetaobject-rs
user, and I'm trying to use QEnum-deriving enum as a property type. My code compiles, but at runtime qml sees the property typeObject
instead ofint
. Any hints are welcome. The minimal (broken) example and output are below.The text was updated successfully, but these errors were encountered: