Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-103186

QML enums not supported in inline components

    XMLWordPrintable

Details

    • Linux/X11

    Description

      I would expect inline components to work exactly the same as external components defined in a .qml file. However, the following code doesn't work, since the enum cannot be accessed:

      #!/usr/bin/env qml
      import QtQuick
      import QtQuick.Window
      
      Window {
          width: 320; height: 240
          visible: true
      
          component MyComponent: Rectangle {
              enum MyColorEnum { Red, Green }
              property int myColor
      
              anchors.fill: parent
              color: myColor === MyComponent.Green ? "green" : "red"
      
              Text { text: MyComponent.MyColorEnum.Green }
          }
      
          MyComponent { myColor: MyComponent.Green }
      }
      

      When the inline MyComponent is replaced with an external MyComponent.qml file with the same content, it works as expected.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qtqmlteam Qt Qml Team User
            bweimer Bernd Weimer
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes