[Qt-qml] enumerations in QML

henrik.hartz at nokia.com henrik.hartz at nokia.com
Fri Aug 6 07:42:02 CEST 2010


Could you spec this out in detail in a http://bugreports.qt.nokia.com entry? Then, use the voting system there rather than this list, makes it easier to track how many actually want it :)

Thanks,
Henrik

On 5. aug. 2010, at 21.47, ext alan.westbrook at nokia.com wrote:

> 
> 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
> 
> 
> _______________________________________________
> Qt-qml mailing list
> Qt-qml at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-qml





More information about the Qt-qml mailing list