From 227accf0a3d1e177ece05d988196510f29240f58 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Mon, 5 Nov 2012 13:51:54 +0200 Subject: [PATCH] Fix hellowindow example generating excess timers The example was creating a new timer on every expose event, which quickly leads into massive excess of timeout signals. Fixed by only creating one timer. Task-number: QTBUG-27836 Change-Id: Ia6ed1bd9575e296f4c6c5b12509095e4d5c016dd Reviewed-by: Jonathan Liu Reviewed-by: Friedemann Kleint --- examples/opengl/hellowindow/hellowindow.cpp | 11 ++++++----- examples/opengl/hellowindow/hellowindow.h | 2 ++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/examples/opengl/hellowindow/hellowindow.cpp b/examples/opengl/hellowindow/hellowindow.cpp index 3c314d9bc2..7770949d45 100644 --- a/examples/opengl/hellowindow/hellowindow.cpp +++ b/examples/opengl/hellowindow/hellowindow.cpp @@ -60,8 +60,7 @@ Renderer::Renderer(const QSurfaceFormat &format, Renderer *share, QScreen *scree } HelloWindow::HelloWindow(const QSharedPointer &renderer) - : m_colorIndex(0) - , m_renderer(renderer) + : m_colorIndex(0), m_renderer(renderer), m_timer(0) { setSurfaceType(QWindow::OpenGLSurface); setWindowFlags(Qt::Window | Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint); @@ -84,9 +83,11 @@ void HelloWindow::exposeEvent(QExposeEvent *event) render(); - QTimer *timer = new QTimer(this); - connect(timer, SIGNAL(timeout()), this, SLOT(render())); - timer->start(10); + if (!m_timer) { + m_timer = new QTimer(this); + connect(m_timer, SIGNAL(timeout()), this, SLOT(render())); + m_timer->start(10); + } } void HelloWindow::mousePressEvent(QMouseEvent *) diff --git a/examples/opengl/hellowindow/hellowindow.h b/examples/opengl/hellowindow/hellowindow.h index a3e9fc5f96..adb85c1a6e 100644 --- a/examples/opengl/hellowindow/hellowindow.h +++ b/examples/opengl/hellowindow/hellowindow.h @@ -49,6 +49,7 @@ QT_BEGIN_NAMESPACE class QOpenGLContext; +class QTimer; QT_END_NAMESPACE class Renderer : public QObject @@ -107,4 +108,5 @@ private: int m_colorIndex; QColor m_color; const QSharedPointer m_renderer; + QTimer *m_timer; };