QElapsedTimer timer;
timer.start();
slowOperation1();
qDebug() << "The slow operation took" << timer.elapsed() << "milliseconds";
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;
}
时间过去后,再次获取当前时间,并计算差值。
qint64 QElapsedTimer::elapsed() const Q_DECL_NOTHROW
{
return QDateTime::currentMSecsSinceEpoch() - t1;
}
关于qt - 如何停止QElapsedTimer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37108220/