11-16-2012 12:34 PM
Hello everyone ![]()
QtQuick has a Connections element to access C++ signals in QML and handle them. This looks like this:
Connections {
target: live
onLiveUpdateStarted: {
console.debug("qml onLiveUpdateStarted")
updatingLiveData.running = true
updatingLiveData.visible = true
}
onLiveUpdateFinished: {
console.debug("qml onLiveUpdateFinished")
updatingLiveData.running = false
updatingLiveData.visible = false
}
}
where "live" is set through main.cpp: viewer.rootContext()->setContextProperty("live", live);
How do I do this connection with Cascades as Connections doesn't seem to be available.
Best Regards,
Sebastian
Solved! Go to Solution.
11-16-2012 12:44 PM
Actually the Connections element is still available, but you have to "import QtQuick 1.0" first to get it into the namespace. At that point, because it's not a visual node, you'll also need to place it in an attachedObjects list instead of just out with the rest of the page content as you could in Qt QML.
You may not need it, however. Another option that doesn't require bringing in QtQuick is to make direct connections to the signals, something like this:
onCreationCompleted: {
live.liveUpdateStarted.connect(someFunction);
live.liveUpdateFinished.connect(someOtherFunction) ;
}
Then you'd obviously define regular JavaScript functions (e.g. someFunction) with the same content as the handlers you showed.
11-16-2012 01:15 PM
Thanks, that's even easier than with Connections.
How could I have found it in any documentation? Cause this is the most annoying thing for me in Cascades at the moment. QtQuick/Qt Creator has this wonderful QtAssistant, but I couldn't find anything like that here. Only the online (!) API reference, but the navigation is hard there.
Did I missed something?
Best Regards,
Sebastian
11-16-2012 02:24 PM
02-05-2013 01:41 AM
From the docs:
"By default, a signal is emitted for every connection you make; two signals are emitted for duplicate connections."
The problem I'm having is that calling connect() in QML is causing the connections to stack, but I can't see a way in QML to clear the connections or ensure there is only one e.g. from the Cascades docs:
Button {
id: increaseButton
text: "Increase the value"
onClicked: {
cppObject.valueChanged.connect
(increaseButton.onCppValueChanged);
cppObject.value = cppObject.value + 1;
}
function onCppValueChanged (val) {
increaseButton.text = "Set value to " + (val + 1);
}
}
The second time you click the button onCppValueChanged will actually be connected twice and will be called twice. Is there a way in QML to do something like:
cppObject.mySignal.connect(myFunc, Qt::UniqueConnection);
I tried this but it didn't work:
cppObject.mySignal.disconnect(myFunc);
cppObject.mySignal.connect(myFunc);
02-07-2013 09:20 PM
I ended up solving my problem here: http://supportforums.blackberry.com/t5/Cascades-De