Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [SOLVED]expose enum method to qml
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]expose enum method to qml

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 8.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    leaf
    wrote on last edited by
    #1

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

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

    1 Reply Last reply
    0
    • T Offline
      T Offline
      task_struct
      wrote on last edited by
      #2

      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

      "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

      • Linu...
      1 Reply Last reply
      0
      • L Offline
        L Offline
        leaf
        wrote on last edited by
        #3

        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;@

        1 Reply Last reply
        0
        • L Offline
          L Offline
          leaf
          wrote on last edited by
          #4

          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()

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved