Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Calcultate fps



  • Hi,

    I want to display number of frame per second (fps) in my user interface, is there a simple way to do this in Qt ? and in QML ?

    Regards



  • The example below illustrates how this can be done, it is based on how this is done internally in Qt:

    @class FPS : public QWidget
    {

    public:
    FPS() : m_frameCount(0) {}

    void paintEvent(QPaintEvent *e) {
        if (m_frameCount == 0) {
             m_time.start();
        } else {
            printf("FPS is %f ms\n", m_time.elapsed() / float(m_frameCount));
        }
        m_frameCount++;
    
        // Painting goes here...
    
    }
    
    QTime m_time;
    int m_frameCount;
    

    };@



  • Nice, thanks for answer.



  • That would gave you 'time elapsed per frame'. If you want 'frame per second' (FPS), your printf should be:

    @printf("FPS is %f\n", m_frameCount / (float(m_timer.elapsed()) / 1000.0f));@


Log in to reply