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

It should be possible to give components defined inline a type-name too.

    XMLWordPrintable

Details

    Description

      The QML documentation seems to suggest that it is optional to define a custom component
      in a separate QML file, in fact it not always is, as components defined inline cannot be given
      a type-name, only an instance-id.

      import Qt 4.7
      
      Rectangle {
          width: 640; height: 480;
      
          // This works because an instance of "blueRect" is created (?) here
          Component  {
              id: "blueRect"
              Rectangle {
                  width: 100
                  height: 100
                  color: "blue"
              }
          }
      
          Repeater {
              model: 1
              delegate: blueRect  // blue-rect instance used here
          }
      
          // Can't instantiate a component from an instance-id
          blueRect { x: 200; y: 100 }
      
          // This syntax is not supported. The component needs to be moved to RedRect.qml
          Component RedRect {
              Rectangle {
                  width: 100
                  height: 100
                  color: "red"
              }
          }
      
          // None of this will only work unless RedRect is moved to RedRect.qml
          RedRect { x: 200; y: 200 }
          RedRect { x: 300; y: 300 }
          Repeater {
              model: 1
              delegate: RedRect {}
          }
      }
      

      Attachments

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

        Activity

          People

            martinj Martin Jones
            mathiasm Mathias Malmqvist
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes