Click here to Skip to main content
15,667,847 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am currently working in a qt project, my requirement is to log a data on a specific time (for eg: 10:14:21:100) when system clock reach this 100 msec on every second i need to log the data. Any body tell me how to achieve that... Thanks

What I have tried:

I am getting the data every 1 sec of random msec.
Updated 1-Mar-22 3:41am
Richard MacCutchan 1-Mar-22 7:20am    
You can use a timer to get notified on a regular basis, but it is unlikely that you will get the interrupt at the exact time you are looking for. Timer interrupts are sent after the interval has elapsed, but they are not guaranteed accurate to any level.
Member 15253975 1-Mar-22 8:59am    
could you please give any examples?
I don't understand
Richard MacCutchan 1-Mar-22 10:03am    
Sorry, I don't know QT, but maybe QTimer Class | Qt Core 5.15.8[^] will help.

1 solution

I'm not familiar with qt, but it probably has a "time now" function that includes milliseconds. Something like this should then work. You have to calculate how long to sleep until the next multiple of 100 msecs occurs:
int sleep_time()
   auto now = get_time();
   int curr_msecs = now.msecs;
   int wakeup_msecs = (now.msecs / 100) + 100;
   return wakeup_msecs - now.msecs;

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