Unsolved Passing a variable to a CircularGauge object.
-
Hello guys, i'm doing some modifications to a vehicle HMI, everything is going smooth but my code is reaching thousands lines and using a single file wasn't possible anymore. For that reason i started splitting the code in multiple qml files and then use the Loader object to load them. 99% of the things are working as expected but i have an issue when displaying a variable inside a CircularGauge object.
I'll try to paste some snippets of the code here:
I have a main qml file with several object qith this (please note that useless lines has been removed from the snippet):
property var rpm: 0 ... ... ... Loader { // RPM GAUGE id: rpmGaugeLoader y: 55 x: 5 source: "RpmGauge.qml" } ... ... ...
The RpmGauge.qml is this one (please note that useless lines has been removed from the snippet):
import "CanBusUtils.js" as CanBusUtils CircularGauge { id: rpmGauge minimumValue: 0 maximumValue: 8 style: CircularGaugeStyle { tickmarkStepSize: 1 minorTickmarkCount: 0 tickmarkInset: sport_mode ? 12 : 15 labelInset: sport_mode ? -8 : 0 } Text { id: rpmText anchors.horizontalCenter: rpmGauge.horizontalCenter anchors.top: rpmLabelText.bottom anchors.topMargin: 5 font.pixelSize: 40 color: sport_mode ? "#FF0000" : "#3F497F" text: CanBusUtils.getRPM() } Component.onCompleted: forceActiveFocus() value: CanBusUtils.getRPM() / 1000 Behavior on value { NumberAnimation { duration: 100 } }
}
As you can see i'm using the getRPM() function (loaded from the CanBusUtils.js) to display the RPM and to move the gauge.
CanBusUtils.js:
var rpm = 0; function getRPM() { var identifier = value.charCodeAt(7).toString(16); if (identifier == 1) { rpm = value.substring(0,4); } return +rpm; }
Now, the problem is that the value is always null (not 0, so it's not readed at all) but the strange thing is that if use exactly the same code, but instead of 'displaying' the value in the CircularGauge i use anything else (A Rectangle with a Label for example) the RPM value is correctly displayed.
The only workound i found to make it work is copy the js code inside the main.qml and declare rpm as property, but i do not wat to do that as all the other vechile parameters are inside the CanBusUtils.js file.
Anyone can help? :)
Thanks
edit:
I forgot to mention that due to the Vehicle HMI being closed source, i cannot write any C++ code.
Only Pure QML