2

In Qt all the Classes are having Milliseconds timer . I need to implement Microsecond timer using hardware timer or any Qt classes will not support for Microsecond timer.

Any one please help me how to implement microsecond timer in Qt application code?

demonplus
  • 5,613
  • 12
  • 49
  • 68
raj
  • 53
  • 1
  • 7
  • You may want to look at this also: http://stackoverflow.com/questions/15730765/qt-high-resolution-timer – demonplus Dec 22 '15 at 12:54
  • 2
    Your question is not clear. Do you wish to measure time with microsecond resolution, or do you wish to implement delays with such resolution? These would be very different problems. – Kuba hasn't forgotten Monica Dec 22 '15 at 13:54

2 Answers2

6

You should use QElapsedTimer, wich has nanoseconds precision, as follows:

QElapsedTimer timer;
timer.start();

foo();//TODO your stuff

qDebug() << "The foo() function took" << timer.nsecsElapsed() << "nanoseconds";
César HM
  • 198
  • 2
  • 16
jpo38
  • 20,821
  • 10
  • 70
  • 151
0

I cannot comment so I post answer.

I think you can also use usleep() function from POSIX, just #include < unistd.h >.

Reference on this link .

Junior
  • 259
  • 2
  • 14