Qt测试程序经过的时间

做项目的时候想看看QOpenGLWidget提交渲染的时间,Qt测试程序经过的时间有一个类QElapsedTimer 可以直接使用,还是很方便的:

使用时包含头文件

cpp 复制代码
#include <QElapsedTimer>

测试时间为毫秒单位:

cpp 复制代码
QElapsedTimer timer;
timer.start(); // 开始计时

// 运行代码

qint64 elapsed = timer.elapsed();  // 获取经过的时间(毫秒)
qDebug() << "paintGL函数运行时间: " << elapsed << " 毫秒";

测试时间为微妙单位:

cpp 复制代码
QElapsedTimer timer;
timer.start(); // 开始计时

// 运行代码

qint64 elapsedNanoseconds = timer.nsecsElapsed();
qint64 elapsedMicroseconds = elapsedNanoseconds / 1000;

qDebug() << "paintGL 函数运行时间: " << elapsedMicroseconds << " 微秒";
相关推荐
范特西.i5 天前
QT聊天项目(8)
开发语言·qt
枫叶丹45 天前
【Qt开发】Qt界面优化(七)-> Qt样式表(QSS) 样式属性
c语言·开发语言·c++·qt
十五年专注C++开发5 天前
Qt deleteLater作用及源码分析
开发语言·c++·qt·qobject
kangzerun5 天前
SQLiteManager:一个优雅的Qt SQLite数据库操作类
数据库·qt·sqlite
金刚狼885 天前
qt和qt creator的下载安装
开发语言·qt
追烽少年x5 天前
Qt中使用Zint库显示二维码
qt
谁刺我心5 天前
qt源码、qt在线安装器镜像下载
开发语言·qt
金刚狼885 天前
在qt creator中创建helloworld程序并构建
开发语言·qt
扶尔魔ocy6 天前
【转载】QT使用linuxdeployqt打包
开发语言·qt
YxVoyager6 天前
在VS2017中使用Qt的foreach宏,IntelliSense无法正确识别函数定义
c++·qt