Important: Please read the Qt Code of Conduct -

Update a QML CheckBox from a C++ function

  • Could some please help me, I'm really stuck, and its real important that I find out how to do this. Please.
    I have looked, but can't find the solution.

    I have a CheckBox and a Button Area defined inside my Main.qml file.
    This qml file gets loaded and set as the primary context from inside the main() function of the C++ program. Like this...

        QQuickView v;

    Here's the Button Area... that is inside the Main.qml file.

            Rectangle {
                    width: 100
                    height: 50
                    color: "tomato"
                    Text {
                    anchors.fill: parent
                    text: "DoIt"
                MouseArea {
                    anchors.fill: parent

    ********************** Here is the Checkbox that the C++ needs to Check or unCheck ******************************
    This is what I need to set from the C++ code when I click the above button.

    This CheckBox is also located inside the Main.qml file

        anchors.bottom: parent.bottom
        anchors.margins: 10
        text: "Mirror"        
        Binding { target: chk; property: "checked"; value: }
        onClicked: = chk.checked

    When I press the Button Area on the Main.qml page, a C++ function gets called.

    I need a C++ function call to cause the CheckBox to be checked when I press the Button Area. This needs to happen from the C++ code.

    My problem is, I don't know how to access the CheckBox control from the C++ code. I don't know how to do it.

    How do I do that ?

    Please help me if you can.
    And thank you for helping me.

  • Moderators

    You will need a pointer to that CheckBox on c++ side. For that you can use findChild method. It works by finding the items by objectName. So provide an objectName for your CheckBox and then use findChild.
    Once you get that exact object you can set properties of it using setProperty. In this case you can set CheckBox's checked property to true or false from C++ side.

Log in to reply