Unsolved Reference Error
-
Hi everybody,
I'm just starting in Qt and I have a problem, running this program:import QtQuick 2.3 import QtQuick.Window 2.2 import QtQuick.Controls 1.4 import QtQuick.Controls.Styles 1.4 ApplicationWindow { id: root visible: true minimumHeight: 960 minimumWidth: 640 title: "INGRAVITA" menuBar: MenuBar { Menu { title: qsTr("File") MenuItem { text: qsTr("&Open") onTriggered: console.log("Open action triggered"); } MenuItem { text: qsTr("Exit") onTriggered: Qt.quit(); } } } ListModel { //definimos la secuencia de datos, de aqui luego pediremos los datos q nos interesen id: modelInici ListElement {tipus_funcionalitat: "ENTRENA"} ListElement {tipus_funcionalitat: "METEOROLOGIA"} ListElement {tipus_funcionalitat: "SURT FORA"} } //ListModel Component { // Creem el Delegate que es l'encarregat d'agafar les dades que ens interessen den Model id: delegateInici Button { width: rectangleMenu.width height: rectangleMenu.height/3 text: tipus_funcionalitat style: ButtonStyle { background: Rectangle { implicitWidth: 100 implicitHeight: 25 border.width: control.activeFocus ? 3 : 1 border.color: "grey" radius: 0 gradient: Gradient { GradientStop { position: 0 ; color: control.pressed ? "gainsboro" : "whitesmoke" } GradientStop { position: 1 ; color: control.pressed ? "lightgray" : "gainsboro" } } } } } }//Component delegateInici StackView { id: stack anchors.fill: parent } Component{ id: form1 Column{ anchors.centerIn: parent spacing: 0 Rectangle { //anchors.horizontalCenter: parent.horizontalCenter width: root.width height: root.height/2 gradient: Gradient { GradientStop { position: 0 ; color: "whitesmoke" } GradientStop { position: 1 ; color: "gainsboro" } } Image { id: imageLogo fillMode: Image.PreserveAspectFit source: "/imatges/ingravita_logo.png" anchors.fill: parent onStatusChanged: if (imageLogo.status == Image.Error) console.log ("Background image \"" + source + "\" cannot be loaded") } //Image }//Rectangle Rectangle{ id: rectangleMenu width: root.width height: root.height/2 Column { spacing:0 Repeater { model: modelInici delegate: delegateInici }//Repeater aqui és on "escupim" el nostre Model }//Column } //Rectangle }//Column }//Component Component.onCompleted: stack.push(form1) }//Window
The buttons (delegate) can not acces to the rectangleMenu to get its heigh and weight,
which error am I doing?If I just not use the component, id: form1, it works fine but if I want to use components to organize my code.
When I execute the code in the console appears:
qrc:/qml/ingravita_main.qml:39: ReferenceError: rectangleMenu is not defined
qrc:/qml/ingravita_main.qml:38: ReferenceError: rectangleMenu is not defined
qrc:/qml/ingravita_main.qml:39: ReferenceError: rectangleMenu is not defined
qrc:/qml/ingravita_main.qml:38: ReferenceError: rectangleMenu is not defined
qrc:/qml/ingravita_main.qml:39: ReferenceError: rectangleMenu is not definedThank you very much
-
Hi and welcome to devnet,
Components should be considered like a "separated file" thus you can't access children of them directly. If you want something that is within a component you should write a proper interface from the component. See here for more details.