I'm developing a Blackberry 10 mobile application using the BB Native SDK.
I need to call a QML function into my C++ class. I searched a lot on this but I only found the possibility to call C++ into QML not the inverse. You can check this: QML and C++ integration
Can anyone help me on this?
This is the QML code specifying the function that I need to call which add a marker into my mapview:
Container {
id: pinContainer
objectName: "pinContObject"
...
function addPin(lat, lon, name, address) {
var marker = pin.createObject();
marker.lat = lat;
marker.lon = lon;
...
}
}
MyItem.qml
main.cpp
This should works. Here i am calling a QML function from my C++ class.
Thats what signals and slots are for. You can use the QML Connections for connecting arbitrary signals to arbitrary slots in QML.
http://qt-project.org/doc/qt-4.8/qml-connections.html
and in C++ backend, all you have to do is
From Qt documentation:
http://qt-project.org/doc/qt-5/qtqml-cppintegration-interactqmlfromcpp.html#invoking-qml-methods
Calling
QMetaObject::invokeMethod
one will call proper slot, no matter if it is defined in C++ or QML.