How create a delay 1 nano second or 1 usecond with QTimer in Qt? is it possible?
-
wrote on 14 Oct 2021, 19:20 last edited by
How create a delay 1 nanosecond or 1 microsecond with QTimer in Qt? is it possible?
When I used QTimer delay unit is millisecond... my question is how i can create more accurate delay in qtthanks in advance
QElapsedTimer timer; timer.start(); function_delay(); qDebug()<<timer.nsecsElapsed();
For function delay, I used this method but the delay accuracy is 100 microseconds...
QTimer delay; delay.start(); int DelayTime=0; while(DelayTime < delayNS) { jammingDelayTime=timer.nsecsElapsed(); }
or
std::this_thread::sleep_for(std::chrono::nanoseconds(delayJammingNS));
these methods 100 microseconds is a minimum delay that executed.....I want to delay 1 microsecond or 1 nanosecond...
-
No and I don't see what you want to do with this short timer...
-
wrote on 14 Oct 2021, 19:33 last edited by
@stackprogramer said in How create a delay 1 nano second or 1 usecond with QTimer in Qt? is it possible?:
read::sleep_for(std::chrono::nanoseconds(delayJammingNS));
@JoeCFD But I saw this link when I used method
std::this_thread::sleep_for(std::chrono::nanoseconds(1));
delay is measured with QElapsedTimer timer;
but delay that elapses timer show is 100000 nano second not a 1 nano second..... -
wrote on 14 Oct 2021, 19:51 last edited by
my problem is solved with this method...
std::chrono::nanoseconds(nanosecond).count();
-
wrote on 14 Oct 2021, 20:33 last edited by
Are you sure? In that link:
there is the scheduler, which probably allows no sleeps that are shorter than an timeslice (somewhat around 4 ms - 10 ms, depending on your windows and machine). sleeping less than that is not possible -
wrote on 14 Oct 2021, 20:47 last edited by
@JoeCFD said in How to create a delay 1 nanosecond or 1 second with QTimer in Qt? is it possible?:
Are you sure? In that link:
there is the scheduler, which probably allows no sleeps that are shorter than an timeslice (somewhat around 4 ms - 10 ms, depending on your windows and machine). sleeping less than that is not possibleWhen I used the before method for a nanosecond I measure 100000nano seconds.....the difference was so much....
std::chrono::nanoseconds(nanosecond).count();
but with the up method, I can delay 1000 nanoseconds or 1micro second about accurately .....
My os is ubuntu,qt,gcc...not windows...
This delay function executed on a QThread....thanks good time
1/7