作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
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/
有没有一种方法可以找出 QElapsedTimer 可以运行多长时间而无需重置?该类总是返回一个 qint64,但我不知道这是否对应于它可以测量的最大持续时间。 文档 ( http://qt-proj
我正在开发一个应用程序 (c++),它利用多种类型的硬件同时收集各种类型的数据。常见的使用模式是在各自的线程中运行这些设备的不同接口(interface)(眼球跟踪、运动跟踪、可视化等),这样它们就会
我有一个 GUI 按钮,它调用 shell 脚本来开始录制视频。另外我想要一个 slider 来显示录制进度(最长录制时间为 30 秒)。我构建了以下函数: coid MainWindow::on_r
我是一名优秀的程序员,十分优秀!