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. Sending data from one QML to Another when click on checkbox

Sending data from one QML to Another when click on checkbox

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 1.5k 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
    #1

    hey there I am developing an application, in that i need to send checkbox checked status from mail.qml to graph.qml on each click (check and uncheck)

    my mail.qml is

    import QtQuick 2.7
    import QtQuick.Window 2.2
    import QtQuick.Controls 1.2

    Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    Rectangle
    {
        id: connectButton
        x: 130
        y: 10
        width: 70
        height: 30
        visible: true
        gradient: Gradient
        {
            GradientStop
            {
                position: 0
                color: "#ffffff"
            }
    
            GradientStop
            {
                position: 1
                color: "#000000"
            }
        }
        border.color: "#251f1f"
    
        Text
        {
            id: text1
            text: qsTr("Connect")
            verticalAlignment: Text.AlignVCenter
            horizontalAlignment: Text.AlignHCenter
            transformOrigin: Item.Center
            anchors.fill: parent
            font.pixelSize: 12
        }
        MouseArea
        {
            anchors.fill: parent
    
            onClicked:
            {
                console.log(qsTr("Connect Button Clicked"))// + textEdit.text + '"'))
               loader.source = "Graph.qml"
    
                //To-do
    
                //Connection with aurdino will come here
               /* viewButton.visible = true
                sensorButton.visible = true
                sensorOption.visible = true
                viewOption.visible = true*/
    
    
            }
    
    
        }
    
    }
    
    
    Rectangle {
        id: graphView
        x: 0
        y: 200
        width: 630
        height: 443
       gradient: Gradient {
            GradientStop {
                position: 0
                color: "#ffffff"
            }
    
            GradientStop {
                position: 1
                color: "#000000"
            }
        }
    
    
        Loader
        {
            id: loader
            anchors.bottomMargin: 0
            anchors.leftMargin: 0
            anchors.topMargin: 0
            anchors.rightMargin: 0
            anchors.fill: parent
        }
    }
    
    
    
    Column {
        id:sensorOption
        x:450
        y:80
        visible: true
    
    
        CheckBox {
            text: qsTr("Temperature")
            checked: true
            onClicked:
                if(checked == true)
                {
                     console.log(qsTr("Temperature Sensor selected")+test)
    
                }
            else
                {
                     console.log(qsTr("Temperature Sensor unselected"))
                }
    
    
        }
        CheckBox {
            text: qsTr("Torque")
            onClicked:
                if(checked == true)
                {
                     console.log(qsTr("Torque Sensor selected"))
                }
            else
                {
                     console.log(qsTr("Torque Sensor Unselected"))
                }
        }
        CheckBox
        {
            text: qsTr("Accelerometer")
            onClicked:
                if(checked == true)
                {
                     console.log(qsTr("Accelerometer Sensor selected"))
                }
            else
                {
                     console.log(qsTr("Accelerometer Sensor unselected"))
                }
       }
    }
    

    }

    my graph.qml is

    import QtQuick 2.0
    import QtCharts 2.0

    Item {
    id: graph
    anchors.fill: parent

    ChartView {
        id:chartName
        title: "Sensor"
        anchors.fill: parent
        antialiasing: true
    
        LineSeries {
            id:temperature
            name: "Here name will come from mail.qml"
            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 }
    
    
        }
    
    }
    

    }

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      There is nothing like sending data from one QML to another QML. You need to send the data from one object to another object. Where are you creating the object of Graph.qml ? I did not see any creation of Graph.qml in your main.qml.

      You can pass the data to other object either by signal/slots or calling function in another qml object

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

      R 2 Replies Last reply
      5
      • dheerendraD dheerendra

        There is nothing like sending data from one QML to another QML. You need to send the data from one object to another object. Where are you creating the object of Graph.qml ? I did not see any creation of Graph.qml in your main.qml.

        You can pass the data to other object either by signal/slots or calling function in another qml object

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

        @dheerendra I just loaded graph.qml using loader, I am very new in qt.

        onClicked:
        {
        console.log(qsTr("Connect Button Clicked"))// + textEdit.text + '"'))
        loader.source = "Graph.qml"

        line no 49 to 52

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by dheerendra
          #4

          Define the function called

          1. callRaghavendra(value) in Graph.qml
          2. When you click on the checkbox , inside the signal handler call with
            loader.item.callRaghavendra(<value you would like to pass>)

          Also look for signal/slot communication in QML and function in QML. It will help you.

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

          1 Reply Last reply
          6
          • dheerendraD Offline
            dheerendraD Offline
            dheerendra
            Qt Champions 2022
            wrote on last edited by
            #5

            You can move this issue to SOLVED state.

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

            1 Reply Last reply
            5
            • dheerendraD dheerendra

              There is nothing like sending data from one QML to another QML. You need to send the data from one object to another object. Where are you creating the object of Graph.qml ? I did not see any creation of Graph.qml in your main.qml.

              You can pass the data to other object either by signal/slots or calling function in another qml object

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

              @dheerendra said in Sending data from one QML to Another when click on checkbox:

              calling function in another qml object

              it worked for me
              https://forum.qt.io/topic/46052/use-a-function-in-qml-from-another-qml/4

              1 Reply Last reply
              1

              • Login

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