gpt4 book ai didi

qt - 如何停止QElapsedTimer?

转载 作者:行者123 更新时间:2023-12-02 12:10:12 25 4
gpt4 key购买 nike

    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 会保存当前时间。

来自qelapsedtimer_generic.cpp

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;
}

附注具体实现取决于平台:Windows , Unix , Mac

关于qt - 如何停止QElapsedTimer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37108220/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com