Results 1 to 20 of 25

Thread: How can I get a 30 or 60 frame rate when using QGLWidget? QTimer is not acurate

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Wink Re: How can I get a 30 or 60 frame rate when using QGLWidget? QTimer is not acurate

    Hi friends!

    I think I found a way. just a WHILE(1) and use qApp->processEvents() to avoid a blocked UI. This code is executed when PLAY is pressed. There are no timers.

    Qt Code:
    1. // simulate it for 10 seconds
    2. m_rendered_frames=0;
    3. m_time.start();
    4. while (m_time.elapsed()<=10000) {
    5. QTime now;
    6. now.start();
    7. qApp->processEvents();
    8. m_current_level->Update(0);
    9. m_gl_drawer->updateGL();
    10. m_rendered_frames++;
    11. // sleep a while
    12. if (SIMULATION_UPDATE_INTERVAL_IN_MS-now.elapsed()>0) {
    13. QTest::qSleep(SIMULATION_UPDATE_INTERVAL_IN_MS-now.elapsed());
    14. }
    15. }
    16. // info
    17. float fps=m_rendered_frames/10.0;
    18. QString m=QString("FPS: %1. rendered frames: %2. Timer interval (ms): %3.").arg(fps).arg(m_rendered_frames).arg(SIMULATION_UPDATE_INTERVAL_IN_MS);
    19. QMessageBox::warning(this, "Warning", m);
    To copy to clipboard, switch view to plain text mode 

    It works properly. What do you think?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How can I get a 30 or 60 frame rate when using QGLWidget? QTimer is not acurate

    Event processing is sparse, keys might not be responding or might respond with a delay. That's not a good way to do it. But if it suits your needs...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Retrieval of frame rate in Phonon.
    By Theo Adams in forum Qt Programming
    Replies: 2
    Last Post: 6th July 2010, 19:00
  2. Replies: 1
    Last Post: 23rd April 2009, 09:05
  3. Frame rate problem
    By MrShahi in forum Qt Programming
    Replies: 1
    Last Post: 30th July 2008, 23:06
  4. Change frame rate
    By superutsav in forum General Programming
    Replies: 1
    Last Post: 3rd August 2006, 21:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.