Hi, Maybe this suits your need? -
var Media = (function() { var en = {}; for(i=0; i<arguments.length; i++) { en[arguments[i]] = i; } return en;})("IsGood", "IsAwesome") Media.IsGood 0 Media.IsAwesome 1 Not sure where to put it, since last time I looked I found QML's scoping rules a little odd*, maybe someone else can help there. - Justin * Could be just me - I didn't look that deep, besides you can't do worse than PHP :) On 6/08/10 5:47 AM, Westbrook Alan (Nokia-MS/MtView) wrote: > > On Aug 5, 2010, at 12:10 PM, ext Alex wrote: > >> On Wed, Aug 4, 2010 at 10:03 PM,<bea....@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@trolltech.com > http://lists.trolltech.com/mailman/listinfo/qt-qml _______________________________________________ Qt-qml mailing list Qt-qml@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-qml