Sending data from one QML to Another when click on checkbox



  • 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 }
    
    
        }
    
    }
    

    }



  • 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 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



  • 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.



  • You can move this issue to SOLVED state.




Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.