Timer still running when main QML is not loaded
-
Is your Loader element really called "someloader"? That was just an example id.
Oops. and I see an error in the code I gave you. That should have said
@
running: (someloader.source == "")
@The timer should be in the same file as the Loader itself. Not in the QML that the Loader actually loads.
It's hard to give a more detailed answer without knowing how you have your QML constructed. Do you have any sample code you could share of the section you're having trouble with?
-
@ Timer {
id: decrementTimer
interval: 2000 // 2 seconds
repeat: true
running: (mainLoader.source != "home_aspin.qml")onTriggered: { // do your decrement code here Storage.setSetting("setting",hungertext.text) JScript.decrementcode(); } Component.onCompleted: { Storage.initialize() } }@
@ MouseArea {
id: sleep2home
x: 138
y: 407
width: 95
height: 76
onClicked: {
decrementTimer.start();
mainLoader.source = "QML2";}
}@this is inside my main QML, and i dont put timer codes on my QML2
-
But the Timer and the MouseArea are in the same file, correct?
Just trying to make sure I understand the layout fully.
(If the Timer is in a piece of QML which is loaded by a Loader, and that QML is unloaded, then the timer will stop because it doesn't exist anymore. So the timer has to be persistent somewhere.)