How to read a property of a QtObject in list
-
wrote on 29 Feb 2024, 08:46 last edited by
I have something like:
property var listGraphs: [] QtObject { id: graph property string xmin: "-20" property string xmax: "20" property string zmin: "-20" property string zmax: "20" } -------- listGraphs.push(graph) -------- listGraphs[0].xmin // error undefined
What should be the correct sintax in the last line to read the properties of the QtObject ?
-
I have something like:
property var listGraphs: [] QtObject { id: graph property string xmin: "-20" property string xmax: "20" property string zmin: "-20" property string zmax: "20" } -------- listGraphs.push(graph) -------- listGraphs[0].xmin // error undefined
What should be the correct sintax in the last line to read the properties of the QtObject ?
wrote on 29 Feb 2024, 09:36 last edited by Ronel_qtmasterimport QtQuick 2.12
import QtQuick.Window 2.12Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")property var listGraphs: [] QtObject { id: graph property string xmin: "-20" property string xmax: "20" property string zmin: "-20" property string zmax: "20" } Component.onCompleted: { listGraphs.push(graph) console.log( listGraphs[0].xmin) }
}
-
import QtQuick 2.12
import QtQuick.Window 2.12Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")property var listGraphs: [] QtObject { id: graph property string xmin: "-20" property string xmax: "20" property string zmin: "-20" property string zmax: "20" } Component.onCompleted: { listGraphs.push(graph) console.log( listGraphs[0].xmin) }
}
wrote on 29 Feb 2024, 09:39 last edited by@johngod you should put the last 2 statements in a function and call it.you are using the syntax of a property for a function which is wrong
-
@johngod you should put the last 2 statements in a function and call it.you are using the syntax of a property for a function which is wrong
wrote on 29 Feb 2024, 10:31 last edited by@Ronel_qtmaster I did that, the code I posted was cutted for simplicity. Either way it started to work, maybe it just needed some qmake clean up. Thanks.
-
1/4