C++ QML Integration Demo App
import Felgo 4.0
import QtQuick 2.5
import com.yourcompany.xyz 1.0
App {
id: app
NavigationStack {
AppPage {
title: "Integrate C++ and QML"
Column {
anchors.fill: parent
anchors.margins: 12
AppButton {
text: "myGlobalObject.doSomething()"
onClicked: myGlobalObject.doSomething("TEXT FROM QML")
}
AppButton {
text: "myGlobalObject.counter + 1"
onClicked: {
myGlobalObject.counter = myGlobalObject.counter + 1
}
}
AppText {
text: "Global Context Property Counter: "+myGlobalObject.counter
}
MyQMLType {
id: typeFromCpp
message: "counter / 2 = " + Math.floor(myGlobalObject.counter / 2)
onMessageChanged: console.log("typeFromCpp message changed to '"+typeFromCpp.message+"'")
Component.onCompleted: myGlobalObject.counter = typeFromCpp.increment(myGlobalObject.counter)
onCppTaskFinished: {
myGlobalObject.counter = 0
}
}
AppText {
text: "Custom QML Type Message:\n" + typeFromCpp.message
}
AppButton {
text: "typeFromCpp.startCppTask()"
onClicked: {
typeFromCpp.startCppTask()
}
}
}
Connections {
target: myGlobalObject
function onCounterChanged() {
console.log("Counter changed to "+myGlobalObject.counter)
}
}
}