I'm looking for the equivalent in Qt to GetTickCount()
Something that will allow me to measure the time it takes for a segment of code to run as in:
uint start = GetTickCount(); // do something.. uint timeItTook = GetTickCount() - start;
any suggestions?
The QTimer class provides a high-level programming interface for timers. To use it, create a QTimer, connect its timeout() signal to the appropriate slots, and call start(). From then on, it will emit the timeout() signal at constant intervals.
You can't stop QElapsedTimer , because there is no timer. When you call method start() , QElapsedTimer saves the current time. When elapsed, it gets current time again, and calculate difference.
I think it's probably better to use QElapsedTimer
since that is why the class exists in the first place. It was introduced with Qt 4.7. Note that it is also immuned to system's clock time change.
Example usage:
#include <QDebug> #include <QElapsedTimer> ... ... QElapsedTimer timer; timer.start(); slowOperation(); // we want to measure the time of this slowOperation() qDebug() << timer.elapsed();
How about QTime
? Depending on your platform it should have 1 millisecond accuracy. Code would look something like this:
QTime myTimer; myTimer.start(); // do something.. int nMilliseconds = myTimer.elapsed();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With