Search code examples
multithreadingqttimeqthread

How to get the working time of a thread in c++/qt?


I'm new in the C++ and QT-Programming and want to get the time in milliseconds that a QThread needed to execute one task. Is there any option for this?

Greetings


Solution

  • You'll need to create two signals - one for starting and one for finishing the job. The slot, connected to the start signal, will store the start time like this:

    mStartTime = QDateTime::currentDateTime();
    

    and the slot, connected to the finish signal, will count the difference like this:

    qint64 msecs = mStartTime.msecsTo(QDateTime::currentDateTime());