Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How create a delay 1 nano second or 1 usecond with QTimer in Qt? is it possible?
QtWS25 Last Chance

How create a delay 1 nano second or 1 usecond with QTimer in Qt? is it possible?

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 593 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.
  • S Offline
    S Offline
    stackprogramer
    wrote on 14 Oct 2021, 19:20 last edited by
    #1

    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 qt

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

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 14 Oct 2021, 19:24 last edited by
      #2

      No and I don't see what you want to do with this short timer...

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JoeCFD
        wrote on 14 Oct 2021, 19:30 last edited by
        #3

        https://stackoverflow.com/questions/11063978/c-how-to-sleep-for-a-nanosecond

        1 Reply Last reply
        0
        • S Offline
          S Offline
          stackprogramer
          wrote on 14 Oct 2021, 19:33 last edited by
          #4

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

          1 Reply Last reply
          0
          • S Offline
            S Offline
            stackprogramer
            wrote on 14 Oct 2021, 19:51 last edited by
            #5

            my problem is solved with this method...

                         std::chrono::nanoseconds(nanosecond).count();
            
            1 Reply Last reply
            0
            • J Offline
              J Offline
              JoeCFD
              wrote on 14 Oct 2021, 20:33 last edited by
              #6

              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

              1 Reply Last reply
              1
              • S Offline
                S Offline
                stackprogramer
                wrote on 14 Oct 2021, 20:47 last edited by
                #7

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

                When 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 Reply Last reply
                0

                1/7

                14 Oct 2021, 19:20

                • Login

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