[Interest] Correct way of exposing enum list to QtQuick
Tomasz Olszak
olszak.tomasz at gmail.com
Mon Jul 25 14:35:26 CEST 2016
Thank you for replies,
Seems like there is no easy way of doing that.
Andre still on Qt Quick side list.indexOf(MyEnum.MyEnumValue1) won't work
for list being string list.
Cheers,
Tomasz
2016-07-22 22:13 GMT+01:00 André Somers <andre at familiesomers.nl>:
>
>
> Op 21/07/2016 om 17:17 schreef Tomasz Olszak:
>
> Hi,
>
> I encountered something that bothers me for a few days. I would be
> thankful if someone can point nice workaround for such case:
>
> class MyClass {
> Q_OBJECT
> Q_PROPERTY(MyEnum myEnumProperty ...)
> Q_PROPERTY(QVariantList availableValuesOfMyEnum ...)
> public:
> enum MyEnum {
> MyEnumValue1,
> MyEnumValue1
> }
> Q_ENUM(MyEnum)
> }
>
> From Qt Quick everything works ok except indexOf:
>
> objectOfMyClass.availaleValuesOfMyEnum.indexOf(objectOfMyClass.myEnumProperty)
> gives -1
>
> And it is reasonable because availaleValuesOfMyEnum is list of QVariant
> not list of MyEnum.
>
> If I change type of myEnumProperty to QVariant, indexOf works ok, but
> javascript switch doesn't (QVariant is not int). Additionally
> myEnumProperty is printed nicely in logs from Qt Quick(not raw integer
> value).
>
> Question:
> Does anyone has better idea how to expose list of enums to QtQuick so that
> searching for enum in such list will work out of the box?
>
> Cheers,
> Tomek
>
> You could consider sharing the values as strings instead. With Q_ENUM, it
> is easy to turn the enums into strings. And you can search for a string I
> think.
>
> André
>
>
>
> _______________________________________________
> Interest mailing listInterest at qt-project.orghttp://lists.qt-project.org/mailman/listinfo/interest
>
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160725/dd17f6a0/attachment.html>
More information about the Interest
mailing list