[Interest] Correct way of exposing enum list to QtQuick

Tomasz Olszak olszak.tomasz at gmail.com
Thu Jul 21 17:17:32 CEST 2016


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160721/0bb0cbfd/attachment.html>


More information about the Interest mailing list