Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Load a qml when button click
QtWS25 Last Chance

Load a qml when button click

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 969 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.
  • R Offline
    R Offline
    Raghvendra
    wrote on last edited by Raghvendra
    #1

    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
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      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
      5
      • dheerendraD dheerendra

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

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

        R Offline
        R Offline
        Raghvendra
        wrote on last edited by Raghvendra
        #3

        @dheerendra it worked.

        1 Reply Last reply
        1
        • dheerendraD dheerendra

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

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

          R Offline
          R Offline
          Raghvendra
          wrote on last edited by
          #4

          @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
          1
          • dheerendraD dheerendra

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

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

            R Offline
            R Offline
            Raghvendra
            wrote on last edited by
            #5

            @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
            0

            • Login

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