Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Calling the "Timer" function
QtWS25 Last Chance

Calling the "Timer" function

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 3 Posters 303 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Darq
    wrote on last edited by Darq
    #1

    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
    	}
    
    dheerendraD jsulmJ 2 Replies Last reply
    0
    • D Darq

      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
      	}
      
      dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      @Darq said in Calling the "Timer" function:

      abc.visible = false

      This line is an issue. Try this.

      abc.visible = !abc.visible

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      2
      • D Darq

        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
        	}
        
        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @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)

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        D 1 Reply Last reply
        0
        • jsulmJ jsulm

          @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)

          D Offline
          D Offline
          Darq
          wrote on last edited by Darq
          #4

          Thank you very much, it works now.

          I don't understand the principle of operation of onTriggered, why must the state be true and after the = sign the state false?

          jsulmJ 1 Reply Last reply
          0
          • D Darq

            Thank you very much, it works now.

            I don't understand the principle of operation of onTriggered, why must the state be true and after the = sign the state false?

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @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...

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved