summaryrefslogtreecommitdiffstats
path: root/examples/opengl
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2012-11-05 13:51:54 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-11-05 15:16:06 +0100
commit227accf0a3d1e177ece05d988196510f29240f58 (patch)
tree835dc839eb2a163bb26bccbb7a185c0db93b084b /examples/opengl
parentcbf476242608a575595651a2eb8c40588a4631a4 (diff)
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 <net147@gmail.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Diffstat (limited to 'examples/opengl')
-rw-r--r--examples/opengl/hellowindow/hellowindow.cpp11
-rw-r--r--examples/opengl/hellowindow/hellowindow.h2
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> &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<Renderer> m_renderer;
+ QTimer *m_timer;
};