[SOLVED]expose enum method to qml



  • Hi everyone,
    Is there any way to expost below enum to qml?

    types.h:
    @enum LanguageType {
    Null = 0,
    LanguageZh,
    LanguageTw,
    LanguageEn,
    LanguageFr
    }@



  • Hi,

    AFAIK, your enum should be part of a class registered in QML and you should use Q_ENUMS. See this example: http://lists.qt-project.org/pipermail/interest/2011-December/000255.html



  • Thanks for your help.
    I accroding to the code it is works just has some little problem.
    When I give a value to the enum method then I got 'Cannot assign [undefined] to int'.

    in class.h file:
    @ Q_PROPERTY (LanguageType currentLanguage READ getLanguage WRITE setLanguage NOTIFY languageChanged)
    Q_ENUMS(LanguageType)@

    in qml file:
    @Settings.currentLanguage = Settings.LanguageEn;@



  • It is works well now.
    some marks put here:
    don't forget import the url to qml file.
    qmlRegisterType() should put in main.cpp before veiwer.setSource()


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.