#include// A function to measure the time it takes to execute void myFunction() { // Do some work here } int main() { QTime timer; timer.start(); // Call the function to measure its elapsed time myFunction(); int elapsedTime = timer.elapsed(); qDebug() << "Elapsed Time:" << elapsedTime << "milliseconds"; return 0; }
#includeIn this example, we create a `QTime` object and start the timer. We then execute some code and store the elapsed time in the `elapsedTime` variable. We print this variable to the console. We execute more code and store the elapsed time again, printing it to the console a second time. This allows us to measure the time between two points in the program.int main(int argc, char *argv[]) { QTime timer; timer.start(); // Some code here int elapsedTime = timer.elapsed(); qDebug() << "Elapsed Time:" << elapsedTime << "milliseconds"; // More code here elapsedTime = timer.elapsed(); qDebug() << "Elapsed Time:" << elapsedTime << "milliseconds"; return 0; }