add FpsItem

This commit is contained in:
zhuzichu
2023-08-28 17:14:21 +08:00
parent 82a3f85f10
commit 5fc7ae7e89
5 changed files with 70 additions and 0 deletions

View File

@ -0,0 +1,19 @@
#include "FpsItem.h"
#include <QTimer>
#include <QQuickWindow>
FpsItem::FpsItem()
{
QTimer *timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, [this]{
fps(_frameCount);
_frameCount = 0;
});
connect(this, &QQuickItem::windowChanged, this, [this]{
if (window()){
connect(window(), &QQuickWindow::afterRendering, this, [this]{ _frameCount++; }, Qt::DirectConnection);
}
});
timer->start(1000);
}