January 31, 2012

qtd1d1 qtd1d1
Lab Rat
71 posts

Calculate FPS with QGLWidget - paintGL() is not called

 

Hi,

I am trying to calculate the fps of my application. I know in general how to do it, but my implemented QGLWidget doesn’t work properly. The paintGL() Method doesn’t get called.

That’ how my own Widget GLWidget looks like:

GLWidget.h

  1. #include <QGLWidget>
  2. #include <QTime>
  3.  
  4.  
  5. class GLWidget : public QGLWidget {
  6.  
  7.     Q_OBJECT
  8. public:
  9.     GLWidget(QWidget *parent = 0 );
  10.  
  11.  
  12. protected:
  13.     void paintGL ();
  14.  
  15. private:
  16.     int m_frameCount;
  17.     QTime m_time;
  18.  
  19. };

GLWidget.cpp

  1. #include "glwidget.h"
  2. #include <QDebug>
  3.  
  4. GLWidget::GLWidget(QWidget *parent)
  5.     : QGLWidget(parent)
  6. {
  7.     m_frameCount = 0;
  8. }
  9.  
  10. void GLWidget::paintGL()
  11. {
  12.     if (m_frameCount == 0) {
  13.          m_time.start();
  14.     } else {
  15.         qDebug("FPS is %f ms\n", m_time.elapsed() / float(m_frameCount));
  16.     }
  17.     m_frameCount++;
  18.  
  19.     qDebug() << "frameCount: " << m_frameCount;
  20.     QGLWidget::paintGL();
  21. }

And that’s my main.cpp

  1. int main(int argc, char *argv[])
  2. {
  3.     QApplication a(argc, argv);
  4.  
  5.     QGraphicsScene scene;
  6.  
  7.  
  8.     QGraphicsView view(&scene);
  9.  
  10.     GLWidget *gl = new GLWidget();
  11.  
  12.     view.setViewport(gl);
  13.     view.setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
  14.  
  15.     view.show();
  16.    
  17.     return a.exec();
  18. }

My problem is that it works hardware accerlated but the paintGL() Method doesn’t get called…

Any Ideas?
Thanks

0 replies

 
  ‹‹ SIGSEGV produced when using QNetworkManager after/during post      Qt Solutions Archive ››

You must log in to post a reply. Not a member yet? Register here!