[Interest] QML id as string?
Morten W. J.
morten at winkler.dk
Wed Oct 3 19:25:31 CEST 2018
On onsdag den 3. oktober 2018 19.01.33 CEST Jason H wrote:
> The lexical scoping rules are clear,
What would you expect to be the output of the below?
import QtQuick 2.9
import QtQuick.Window 2.2
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Column {
Repeater {
model: 10
Text { id: myText; text: "I'm item " + index }
}
Text { id: last; text: "Last"}
}
Component.onCompleted:
{
console.log(myText.text);
console.log(last.text);
}
}
On my machine, the output is
qrc:/main.qml:21: ReferenceError: myText is not defined
which is a great example on why you cannot rely on id's as item names.
The id is only unique at type time.
Cheers,
Morten
More information about the Interest
mailing list