Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Load a qml when button click

    General and Desktop
    2
    5
    707
    Loading More Posts
    • 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.
    • R
      Raghvendra last edited by Raghvendra

      Hey. I need to load a graph.qml in main.qml and need to pass some value to from main.qml, so just created a rectangle and creating object of graph.qml and when i click on mouse (in main.qml) I am calling fucntion from graph.qml

      like this mail.qml
      Rectangle {
      id: graphView
      x: 0
      y: 200
      width: 630
      height: 443
      gradient: Gradient {
      GradientStop {
      position: 0
      color: "#ffffff"
      }

                  GradientStop {
                      position: 1
                      color: "#000000"
                  }
              }
      
             Graph
             {
                 id:graphChart
             }
      

      calling function here
      MouseArea
      {
      anchors.fill: parent

                  onClicked:
                  {
      
                      console.log(qsTr("Connect Button Clicked"))// + textEdit.text + '"'))
                     // loader.source = "Graph.qml"
                      graphChart.callme("Temprature","true")
                      console.log(qsTr(myc.connectAurdino("Hello") +"from qml"))
      
                      //To-do
      
                      //Connection with aurdino will come here
                    
                  }
      
      
              }
      

      graph.qml

      Item {
      id: graph
      anchors.fill: parent
      function callme(val1,val2)
      {
      console.log("I am called = "+val1+" =ok= "+val2)
      }
      ChartView {
      id:chartName
      title: "Sensor"
      anchors.fill: parent
      antialiasing: true

          LineSeries {
              id:temperature
              name: val1
              XYPoint { x: 0; y: 0 }
              XYPoint { x: 1.1; y: 2.1 }
              XYPoint { x: 1.9; y: 3.3 }
              XYPoint { x: 2.1; y: 2.1 }
              XYPoint { x: 2.9; y: 4.9 }
              XYPoint { x: 3.4; y: 3.0 }
              XYPoint { x: 4.1; y: 3.3 }
      
      
          }
      

      but I am getting error because graph load before calling fucntion and doesnt find variable which i am assging in graph.qml so it gives refrence error.

      1 Reply Last reply Reply Quote 0
      • dheerendra
        dheerendra Qt Champions 2017 last edited by

        Define one custom property in Graph.qml
        property int val : 1000

        Set the value of this variable when you are creating Graph.qml object

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        R 3 Replies Last reply Reply Quote 5
        • R
          Raghvendra @dheerendra last edited by Raghvendra

          @dheerendra it worked.

          1 Reply Last reply Reply Quote 1
          • R
            Raghvendra @dheerendra last edited by

            @dheerendra I need to load graph.qml when button click, I changed according to you but right now I am displaying graph in rectangle so when application start it load, but i need to load in button click

            1 Reply Last reply Reply Quote 1
            • R
              Raghvendra @dheerendra last edited by

              @dheerendra I did according to you and it works, but the main concern is I need to load graph.qml when click on button (Load graph)

              1 Reply Last reply Reply Quote 0
              • First post
                Last post