Calling the "Timer" function
-
Hello.
I use the "Timer" function to make the image appear. I'm having trouble looping this function. Instead of looping and appearing every few seconds, the image appears twice and disappears. Where is the error that there is no looping?
Image { id: abc source: 'abc.png' anchors.centerIn: parent anchors.verticalCenterOffset: 0 anchors.horizontalCenterOffset: 0 cache: false smooth: true visible: true layer.enabled: true layer.effect: DropShadow { horizontalOffset: 5 verticalOffset: 4 color: "#AA000000" radius: 8 samples: 10 } } Timer { interval: 2000 onTriggered: abc.visible = false running: true repeat: true }
-
@Darq said in Calling the "Timer" function:
abc.visible = false
This line is an issue. Try this.
abc.visible = !abc.visible
-
@Darq It's not clear what you want to achieve. Do you want that the image appears, then disappears after two seconds and appears again after two seconds as long as the timer is running? If so, then why do you set abc.visible to false in onTriggered? You need to set it to inverted value (like: abc.visible = !abc.visible)
-
@Darq said in Calling the "Timer" function:
why must the state be true and after the = sign the state false?
Nobody suggested that.
onTriggered is called on every timeout (in your case after 2sec and then again after 2sec and so on). In your code you set visibiliyt alsways to false - so, how shoult it ever become visible? The logic is quite simple: in onTriggered you change visibility to true if it was false and to false if it was true...