Details
-
Bug
-
Resolution: Duplicate
-
P3: Somewhat important
-
6.6.1
-
None
Description
When running the attached example and clicking in the two rectangles you can see that the "as casting" works with Components defined in separate files but not with components defined inline
Separate files
qml: myOtherRect MyOtherRectangle_QMLTYPE_0(0x6000006edce0) qml: myOtherRect.isAwesome true qml: x MyOtherRectangle_QMLTYPE_0(0x6000006edce0) qml: x.isAwesome true
inline component
qml: myRect MyRectangle(0x6000006ec9a0) qml: myRect.isAwesome true qml: x null qrc:/qt/qml/untitled/Main.qml:28: TypeError: Cannot read property 'isAwesome' of null
I'll put the files contents here and also attach the complete project in case that's easier for reproducing
Main.qml
import QtQuick Window { width: 640 height: 480 visible: true title: qsTr("Hello World") component MyRectangle : Rectangle { property bool isAwesome: true } MyRectangle { id: myRect color: "orange" height: parent.height width: parent.width / 2 MouseArea { anchors.fill: parent onClicked: { console.log("myRect", myRect); console.log("myRect.isAwesome", myRect.isAwesome); var x = myRect as MyRectangle; console.log("x", x); console.log("x.isAwesome", x.isAwesome); } } } MyOtherRectangle { id: myOtherRect color: "yellow" height: parent.height width: parent.width / 2 anchors.right: parent.right MouseArea { anchors.fill: parent onClicked: { console.log("myOtherRect", myOtherRect); console.log("myOtherRect.isAwesome", myOtherRect.isAwesome); var x = myOtherRect as MyOtherRectangle; console.log("x", x); console.log("x.isAwesome", x.isAwesome); } } } }
MyOtherRectangle.qml
import QtQuick Rectangle { property bool isAwesome: true }
Attachments
Issue Links
- duplicates
-
QTBUG-118431 inline component seems can not support cast feature(Type assertions)
-
- Closed
-