20 lines
493 B
C++
Raw Normal View History

2023-08-28 17:14:21 +08:00
#include "FpsItem.h"
#include <QTimer>
#include <QQuickWindow>
2024-04-11 14:51:43 +08:00
FpsItem::FpsItem() {
_fps = 0;
auto *timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, [this] {
2023-08-28 17:14:21 +08:00
fps(_frameCount);
_frameCount = 0;
});
2024-04-11 14:51:43 +08:00
connect(this, &QQuickItem::windowChanged, this, [this] {
if (window()) {
connect(window(), &QQuickWindow::afterRendering, this, [this] { _frameCount++; }, Qt::DirectConnection);
2023-08-28 17:14:21 +08:00
}
});
timer->start(1000);
}