[Qt-qml] enumerations in QML
alan.westbrook at nokia.com
alan.westbrook at nokia.com
Thu Aug 5 21:47:16 CEST 2010
On Aug 5, 2010, at 12:10 PM, ext Alex wrote:
> On Wed, Aug 4, 2010 at 10:03 PM, <bea.lam at nokia.com> wrote:
>> On 05/08/2010, at 2:45 PM, ext Gregory Schlomoff wrote:
>>
>>> Isn't there a way to expose an enum to QML with qRegisterType or something?
>>>
>>
>> If an enum is exposed to Qt's Meta Object system using Q_ENUMS, the enum is automatically available to QML.
>>
>> This is mentioned in http://doc.qt.nokia.com/4.7-snapshot/declarative-tutorials-extending-chapter4-custompropertytypes.html (but probably should be moved to some other reference documentation).
>>
>>
>
>
> Many thanks to all who responded.
>
> I agree with Gregory about weak-typing being an impediment to
> designing reusable and configurable components. I also happened upon
> the trick he mentioned -- using integer properties to represent
> possible values symbolically. However, this does not prevent misuse.
> First, if the symbolic properties are not read-only (const), their
> values could accidentally be modified. Second, nothing prevents a
> plain integer from being used instead of a symbolic name.
>
> Bea's suggestion regarding Q_ENUMS is useful, but it breaks
> encapsulation in those cases where pure QML components need to expose
> enums.
>
> Since the QML API itself uses enums, I think it would be more
> symmetrical to support the feature directly within the QML language,
> regardless of javascript/C++ bindings.
>
> Cheers,
> Alex
I would also like to second Alex's request.
It is of note that using properties for values is also problematic because you cannot have properties which start with an uppercase as the exported enums from C++ are (at least in practice).
Alan
More information about the Qt-qml
mailing list