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

inline component seems can not support cast feature(Type assertions)

    XMLWordPrintable

Details

    • 1f551faa0 (dev)

    Description

      It can reproduce by running  the code below. 

      import QtQuick
      import QtQuick.Window
      
      Window {
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
      
          component InlineListItem: Text {
             required  property string name
      
              height: 50
              text: name
          }
      
           Row{
               id :row
               property InlineListItem  name1: InlineListItem{name: "value"}
      
           }
      
          Text {
              id:text
              property  string name: "value"
              text: name
              height:50
          }
      
          MyText{
              id: mytest
              name:"value"
          }
      
          Item {
              id:item1
             property int parentColor: (row.name1 as InlineListItem)?"1": "0"
          }
      
          Item {
              id:item2
             property int  parentColor: (text as Text )?"2": "0"
          }
      
          Item {
              id:item3
             property int  parentColor: (mytest as MyText )?"3": "0"
          }
      
          Rectangle
          {
              id:rect2
              width: 100
              height:100
              anchors.centerIn: parent
              color: "yellow"
      
              MouseArea{
                  id:mouse1
                  width: 100
                  anchors.fill: parent
                  onClicked: {
                      console.log(item1.parentColor)
                      console.log(item2.parentColor)
                      console.log(item3.parentColor)
                  }
              }
          }
      }
      
      
      

      notes:
      There are three conditions which cover inline component, normal component, the component declared in another file(attached MyText.qml). hit the yellow rectangle to see output of console.

      expecting outcome
      the console output should be
      1
      2
      3
      which means all component can cast successfully.

      real outcome
      the console output is
      0
      2
      3

      Attachments

        1. MyText.qml
          0.1 kB
          Nigel Lu

        Issue Links

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

          Activity

            People

              ulherman Ulf Hermann
              nigel.lu Nigel Lu (Inactive)
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes