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>
This commit is contained in:
Miikka Heikkinen 2012-11-05 13:51:54 +02:00 committed by The Qt Project
parent cbf4762426
commit 227accf0a3
2 changed files with 8 additions and 5 deletions

View File

@ -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 *)

View File

@ -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;
};