Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

Variants in external QML file not initialized when on changed handlers called

$
0
0
This seems inconsistent behaviour, can someone please tell me why this breaks and how to get around it? Starting with a default qtquick 2 application I add the following to the top level Rectangle in main.qml:     Item {         id: inititem         property real f0: 20     }       Rectangle {         id: one         width: parent.width         height: 20         color: "red"           property var listt: [1, 2, 3]         property real f0: inititem.f0           onF0Changed: {             console.log("one f0 changed")             console.log(listt)             console.log(width)         }     }       Two {         id: two         f0: inititem.f0     } and in the file Two.qml have: import QtQuick 2.0   Rectangle {     width: parent.width     height: 20     color: "blue"       property var listt: [1, 2, 3]     property real f0: 0       onF0Changed: {         console.log("two f0 changed")         console.log(listt)         console.log(width)     } } To me the items with id “one” and “two” should be identical, except two is moved to an external file to help organize the code. However, after running the program I get the output: two f0 changed undefined 0 one f0 changed [1,2,3] 360 Why is the variant list in the external QML file (and it’s width) undefined when f0 is changed, while everything works when I keep it in a single QML file? How can I get around this? Thanks

Viewing all articles
Browse latest Browse all 4972

Trending Articles