QElapsedTimer timer;
timer.start();
slowOperation1();
qDebug() << "The slow operation took" << timer.elapsed() << "milliseconds";
Run Code Online (Sandbox Code Playgroud)
http://doc.qt.io/qt-5/qelapsedtimer.html#invalidate
之后qDebug()我想停止这个计时器.我在那里看不到停止功能,也没有单击属性.
出路是什么?
你不能停下来QElapsedTimer,因为没有计时器.调用方法时start(),QElapsedTimer保存当前时间.
void QElapsedTimer::start() Q_DECL_NOTHROW
{
restart();
}
qint64 QElapsedTimer::restart() Q_DECL_NOTHROW
{
qint64 old = t1;
t1 = QDateTime::currentMSecsSinceEpoch();
t2 = 0;
return t1 - old;
}
Run Code Online (Sandbox Code Playgroud)
当经过时,它再次获得当前时间,并计算差异.
qint64 QElapsedTimer::elapsed() const Q_DECL_NOTHROW
{
return QDateTime::currentMSecsSinceEpoch() - t1;
}
Run Code Online (Sandbox Code Playgroud)