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 ?


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

    @class FPS : public QWidget

    FPS() : m_frameCount(0) {}

    void paintEvent(QPaintEvent *e) {
        if (m_frameCount == 0) {
        } else {
            printf("FPS is %f ms\n", m_time.elapsed() / float(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