connecting C++ slot to signal from QML Component
-
Hi all -
On this page, there's a good description of connecting a QML signal to a C++ slot, providing that the QML component is created within C++. I need to connect a C++ slot to a signal coming from a QML object that isn't defined by the C++ class with the slot.
Here's a snippet of my QML:
GridView { id: equipmentView // the model selection is complex, but it works. model: (zoneModel.listSize() > 0) ? (zoneSelected === 0) ? equipmentModel.uuidList : (zoneSelected > 0 && zoneModel.listSize() > zoneSelected) ? zoneModel.getZone(zoneSelected).equipmentList : null : null delegate: Item { id: card property string uuid: equipmentModel.getEquipmentItem(model.modelData).uuid() signal switchClicked(string uuid, bool on) Switch { id: onOffSwitch onClicked: { card.switchClicked(card.uuid, onOffSwitch.checked) } } } }
Is it possible to connect this signal to a C++ slot, or do I need to create this QML entity from with C++ in order to do so?
Thanks...
-
@GrecKo yes I know which C++ object (it's the instantiation of my EquipmentModel, of which there will be only one). So...how do I represent the C++ object in the QML?
And, not that it would be a problem, but...is your example a signal/slot usage, or are you just calling a C++ method?
EDIT: holy cow...it actually works!
onSwitchClicked: (uuid, onOff) => { equipmentModel.receiveQmlSignal(uuid, onOff) }
I didn't realize you could do that. Wow...mind blown.
Thanks, @GrecKo.
-
M mzimmers has marked this topic as solved on