White-Oak / qml-rust

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

impl QMetaTypable for f64 is missing #5

Closed nbigaouette closed 7 years ago

nbigaouette commented 7 years ago

According to the doc, only String and i32 implement QMetaTypable. This means one can't pass a floating point value from/to QML.

Could an impl be added for either f32 or f64?

Thanks!

nbigaouette commented 7 years ago

Related doc: https://white-oak.github.io/qml-rust/qml/trait.QMetaTypable.html#tymethod.metatype

White-Oak commented 7 years ago

@nbigaouette I've added both f32 and f64 as QMetaTypables in https://github.com/White-Oak/qml-rust/commit/eec868f926bdd0ff3a46cf0f6b8e34759730fa9e

Check it out

nbigaouette commented 7 years ago

Nice thanks, will have a look soon.

nbigaouette commented 7 years ago

I still can't use an f32 as a Q_OBJECT!() property...

I get these errors:

<qml macros>:67:56: 67:61 error: the trait bound `f32: std::convert::From<qml::QVariant>` is not satisfied [E0277]
<qml macros>:67 iter . next (  ) ) ; let property : $ proptype = next . into (  ) ; self . $
                                                                       ^~~~~
src/actioncoil.rs:40:1: 73:4 note: in this expansion of Q_OBJECT! (defined in <qml macros>)
<qml macros>:67:56: 67:61 help: run `rustc --explain E0277` to see a detailed explanation
<qml macros>:67:56: 67:61 help: the following implementations were found:
<qml macros>:67:56: 67:61 help:   <f32 as std::convert::From<i8>>
<qml macros>:67:56: 67:61 help:   <f32 as std::convert::From<i16>>
<qml macros>:67:56: 67:61 help:   <f32 as std::convert::From<u8>>
<qml macros>:67:56: 67:61 help:   <f32 as std::convert::From<u16>>
<qml macros>:67:56: 67:61 note: required because of the requirements on the impl of `std::convert::Into<f32>` for `qml::QVariant`
src/actioncoil.rs:82:29: 82:38 error: the trait bound `f32: std::convert::From<&qml::QVariant>` is not satisfied [E0277]
src/actioncoil.rs:82         let inductance_mh = f32::from(self.get_inductance_mh());
                                                 ^~~~~~~~~
src/actioncoil.rs:82:29: 82:38 help: run `rustc --explain E0277` to see a detailed explanation
src/actioncoil.rs:82:29: 82:38 help: the following implementations were found:
src/actioncoil.rs:82:29: 82:38 help:   <f32 as std::convert::From<i8>>
src/actioncoil.rs:82:29: 82:38 help:   <f32 as std::convert::From<i16>>
src/actioncoil.rs:82:29: 82:38 help:   <f32 as std::convert::From<u8>>
src/actioncoil.rs:82:29: 82:38 help:   <f32 as std::convert::From<u16>>
src/actioncoil.rs:82:29: 82:38 note: required by `std::convert::From::from`

Using f32::from() might not be the best way to do it, but I can use i32::from() and String::from() just fine...

White-Oak commented 7 years ago

@nbigaouette whoops, sorry, it's because I forgot to implement Into for QVariant and f32, f64. I'll get it done today/