#include "stopwatch.h" #include "util.h" StopWatch::StopWatch() : m_elapsed(std::make_unique()) {} void StopWatch::start() { m_elapsed->start(); m_timer = std::make_unique(nullptr); connect(m_timer.get(), SIGNAL(timeout()), this, SLOT(updateTimer())); m_timer->start(18); } void StopWatch::updateTimer() { // auto nu = std::chrono::steady_clock::now(); // std::chrono::duration diff = nu - m_startTime; // elapsedTime = diff; // m_timeElapsedLabel->setText(msfloatToHumanReadableString(diff.count())); qint64 ms = m_elapsed->elapsed(); msfloatToHumanReadableString(ms); if (m_timer) { int interval = 18; if (ms >= 10000) { int rem = ms % 1000; interval = 1000 - rem; } else if (ms >= 1000) { interval = 100; } m_timer->start(interval); } }