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

Shorthand Component binding does not work inside inline components

    XMLWordPrintable

Details

    • All

    Description

      QML has this interesting feature that allows binding arbitrary component definitions to QQmlComponent* typed properties without a Component wrapper. But it doesn't work inside inline component definitions. It prints an error on 6.5 and dev, and also crashes on 5.15 if your inline component happens to contain an id.

      The following snippet does NOT crash on 5.15, but print the following error on 6.5/dev:

      import QtQuick 2.15
      
      QtObject {
          property QtObject explicit: Loader {
              sourceComponent: Component {
                  QtObject {}
              }
          }
          property QtObject shortcut: Loader {
              // Shorthand syntax works fine, as usual.
              sourceComponent: QtObject {}
          }
          component Inline : Loader {
              // Comment out next line to avoid QML engine error
              sourceComponent: QtObject {}
          }
      }
      
      main.qml:15:26: Cannot assign object of type "QtObject" to property of type "QQmlComponent*" as the former is neither the same as the latter nor a sub-class of it.
      

      Meanwhile, this snippet DOES crash on 5.15, and still prints a warning on 6.5/dev:

      import QtQuick 2.15
      import QtQuick.Templates 2.15 as T
      
      Item {
          component ABC :
          T.PageIndicator {
              id: control
      
              delegate: Item {}
          }
          ABC {}
      }
      

      Somehow wrapping that delegate Item in a Component or removing id fixes it.

      Reproducible with any type that has a property of Component type. Loader is just one the simplest I found in QtQuick module.

      Attachments

        Issue Links

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

          Activity

            People

              qtqmlteam Qt Qml Team User
              ratijas ivan tkachenko
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes