Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Calcultate fps
QtWS25 Last Chance

Calcultate fps

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 18.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    apap_
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sigrid
      wrote on last edited by
      #2

      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;
      

      };@

      1 Reply Last reply
      0
      • A Offline
        A Offline
        apap_
        wrote on last edited by
        #3

        Nice, thanks for answer.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mchiasson
          wrote on last edited by
          #4

          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));@

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved