Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to read a property of a QtObject in list
Forum Updated to NodeBB v4.3 + New Features

How to read a property of a QtObject in list

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 265 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    johngod
    wrote on 29 Feb 2024, 08:46 last edited by
    #1

    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 ?

    R 1 Reply Last reply 29 Feb 2024, 09:36
    0
    • J johngod
      29 Feb 2024, 08:46

      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 ?

      R Offline
      R Offline
      Ronel_qtmaster
      wrote on 29 Feb 2024, 09:36 last edited by Ronel_qtmaster
      #2

      import QtQuick 2.12
      import QtQuick.Window 2.12

      Window {
      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)
      }
      

      }

      R 1 Reply Last reply 29 Feb 2024, 09:39
      0
      • R Ronel_qtmaster
        29 Feb 2024, 09:36

        import QtQuick 2.12
        import QtQuick.Window 2.12

        Window {
        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)
        }
        

        }

        R Offline
        R Offline
        Ronel_qtmaster
        wrote on 29 Feb 2024, 09:39 last edited by
        #3

        @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

        J 1 Reply Last reply 29 Feb 2024, 10:31
        0
        • R Ronel_qtmaster
          29 Feb 2024, 09:39

          @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

          J Offline
          J Offline
          johngod
          wrote on 29 Feb 2024, 10:31 last edited by
          #4

          @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 Reply Last reply
          0
          • J johngod has marked this topic as solved on 29 Feb 2024, 10:31

          1/4

          29 Feb 2024, 08:46

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved