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; v.setSource(QUrl::fromLocalFile("main.qml")); v.show();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 onClicked: SomeClass.foo() } }********************** 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
CheckBox { id:chk anchors.bottom: parent.bottom anchors.margins: 10 text: "Mirror" Binding { target: chk; property: "checked"; value: FieldPtr.currentFieldPtr.map.Mirror.value } onClicked: FieldPtr.currentFieldPtr.map.Mirror.value = 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. -
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; v.setSource(QUrl::fromLocalFile("main.qml")); v.show();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 onClicked: SomeClass.foo() } }********************** 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
CheckBox { id:chk anchors.bottom: parent.bottom anchors.margins: 10 text: "Mirror" Binding { target: chk; property: "checked"; value: FieldPtr.currentFieldPtr.map.Mirror.value } onClicked: FieldPtr.currentFieldPtr.map.Mirror.value = 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.@arealperson
You will need a pointer to thatCheckBoxon c++ side. For that you can usefindChildmethod. It works by finding the items byobjectName. So provide anobjectNamefor yourCheckBoxand then usefindChild.
Once you get that exact object you can set properties of it usingsetProperty. In this case you can setCheckBox'scheckedproperty to true or false from C++ side.