Click here to Skip to main content
14,363,089 members
Rate this:
Please Sign up or sign in to vote.
See more:
I saw there is SetTimer, but if I want that after 10 seconds something happens, for example if I have a function ChangeColor and I want it happens after 10 seconds, how must I write

What I have tried:

In internet I found :
SetTimer (1, 1000, null);


but I don't know I must I write with a function, when I used Qt there was single slot
Posted
Updated 19-Sep-19 2:56am
v3
Comments
Member 14594285 18-Sep-19 10:02am
   
single slot sorry
Stefan_Lang 18-Sep-19 10:26am
   
You can use the green [Improve question] link at the lower right of your posting to modify it.
Member 14594285 18-Sep-19 10:33am
   
thanks
Rate this:
Please Sign up or sign in to vote.

Solution 1

Code samples gently provided by The Documentation: Using Timers - Windows applications | Microsoft Docs[^].
   
Comments
Member 14594285 18-Sep-19 12:20pm
   
yes, but I saw that there isn't a function like QTimer::SingleSlot()
this method it's longer
CPallini 18-Sep-19 12:37pm
   
That's life. :-)
Rick York 18-Sep-19 21:52pm
   
Once the timer event has been serviced you can kill the timer and then you have a one-shot timer.
Member 14594285 19-Sep-19 3:49am
   
I solved
CPallini 19-Sep-19 3:59am
   
Well done.
Maciej Los 19-Sep-19 4:21am
   
5ed!
Rate this:
Please Sign up or sign in to vote.

Solution 2

The answer of CPallini is correct, but you should write your code more event oriented.

This mean WHEN (and only when) the color is changed you should do something. For instance post a message (or start a one time timer) that the color is changed and handle it somewhere.

Polling regularly on some constant value is a waiste of cpu-power and energy and slows your code. And last but not least it is a source of weired bugs when you poll on different states...
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100