Click here to Skip to main content
15,898,374 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 1: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

Code samples gently provided by The Documentation: Using Timers - Windows applications | Microsoft Docs[^].
 
Share this answer
 
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.
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...
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900