Use QOpenGLWindow with the frameSwapped signal. This is my example with Qt 6.7 that prints delta time to the console:

main.cpp

Qt Code:
  1. #include <QtCore/QElapsedTimer>
  2. #include <QtGui/QOpenGLFunctions>
  3. #include <QtGui/QSurfaceFormat>
  4. #include <QtOpenGL/QOpenGLWindow>
  5. #include <QtWidgets/QApplication>
  6.  
  7. class OpenGLWindow : public QOpenGLWindow, private QOpenGLFunctions
  8. {
  9. public:
  10.  
  11. OpenGLWindow()
  12. {
  13. setTitle("OpenGL ES 2.0, Qt6, C++");
  14. resize(380, 380);
  15.  
  16. QSurfaceFormat surfaceFormat;
  17. surfaceFormat.setSwapInterval(1);
  18. connect(this, SIGNAL(frameSwapped()), this, SLOT(update()));
  19. setFormat(surfaceFormat);
  20. }
  21.  
  22. private:
  23.  
  24. void initializeGL() override
  25. {
  26. initializeOpenGLFunctions();
  27. glClearColor(0.2f, 0.2f, 0.2f, 1.f);
  28. m_elapsedTimer.start();
  29. }
  30.  
  31. void resizeGL(int w, int h) override
  32. {
  33. glViewport(0, 0, w, h);
  34. }
  35.  
  36. void paintGL() override
  37. {
  38. float dt = m_elapsedTimer.elapsed() / 1000.f;
  39. m_elapsedTimer.restart();
  40. qDebug() << dt;
  41. glClear(GL_COLOR_BUFFER_BIT);
  42. }
  43.  
  44. private:
  45. QElapsedTimer m_elapsedTimer;
  46. };
  47.  
  48. int main(int argc, char *argv[])
  49. {
  50. QApplication::setAttribute(Qt::ApplicationAttribute::AA_UseDesktopOpenGL);
  51. QApplication app(argc, argv);
  52. OpenGLWindow w;
  53. w.show();
  54. return app.exec();
  55. }
To copy to clipboard, switch view to plain text mode