1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtCore module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qbasictimer.h"
43 #include "qabstracteventdispatcher.h"
44 #include "qabstracteventdispatcher_p.h"
50 \brief The QBasicTimer class provides timer events for objects.
54 This is a fast, lightweight, and low-level class used by Qt
55 internally. We recommend using the higher-level QTimer class
56 rather than this class if you want to use timers in your
57 applications. Note that this timer is a repeating timer that
58 will send subsequent timer events unless the stop() function is called.
60 To use this class, create a QBasicTimer, and call its start()
61 function with a timeout interval and with a pointer to a QObject
62 subclass. When the timer times out it will send a timer event to
63 the QObject subclass. The timer can be stopped at any time using
64 stop(). isActive() returns true for a timer that is running;
65 i.e. it has been started, has not reached the timeout time, and
66 has not been stopped. The timer's ID can be retrieved using
69 The \l{widgets/wiggly}{Wiggly} example uses QBasicTimer to repaint
70 a widget at regular intervals.
72 \sa QTimer, QTimerEvent, QObject::timerEvent(), Timers, {Wiggly Example}
77 \fn QBasicTimer::QBasicTimer()
79 Contructs a basic timer.
84 \fn QBasicTimer::~QBasicTimer()
86 Destroys the basic timer.
90 \fn bool QBasicTimer::isActive() const
92 Returns true if the timer is running and has not been stopped; otherwise
99 \fn int QBasicTimer::timerId() const
101 Returns the timer's ID.
103 \sa QTimerEvent::timerId()
107 \fn void QBasicTimer::start(int msec, QObject *object)
109 Starts (or restarts) the timer with a \a msec milliseconds timeout. The
110 timer will be a Qt::CoarseTimer. See Qt::TimerType for information on the
111 different timer types.
113 The given \a object will receive timer events.
115 \sa stop() isActive() QObject::timerEvent() Qt::CoarseTimer
117 void QBasicTimer::start(int msec, QObject *obj)
119 QAbstractEventDispatcher *eventDispatcher = QAbstractEventDispatcher::instance();
120 if (!eventDispatcher) {
121 qWarning("QBasicTimer::start: QBasicTimer can only be used with threads started with QThread");
125 eventDispatcher->unregisterTimer(id);
126 QAbstractEventDispatcherPrivate::releaseTimerId(id);
130 id = eventDispatcher->registerTimer(msec, Qt::CoarseTimer, obj);
136 Starts (or restarts) the timer with a \a msec milliseconds timeout and the
137 given \a timerType. See Qt::TimerType for information on the different
140 The given \a object will receive timer events.
142 \sa stop() isActive() QObject::timerEvent() Qt::TimerType
144 void QBasicTimer::start(int msec, Qt::TimerType timerType, QObject *obj)
146 QAbstractEventDispatcher *eventDispatcher = QAbstractEventDispatcher::instance();
147 if (!eventDispatcher) {
148 qWarning("QBasicTimer::start: QBasicTimer can only be used with threads started with QThread");
152 eventDispatcher->unregisterTimer(id);
153 QAbstractEventDispatcherPrivate::releaseTimerId(id);
157 id = eventDispatcher->registerTimer(msec, timerType, obj);
163 \sa start() isActive()
165 void QBasicTimer::stop()
168 QAbstractEventDispatcher *eventDispatcher = QAbstractEventDispatcher::instance();
170 eventDispatcher->unregisterTimer(id);
171 QAbstractEventDispatcherPrivate::releaseTimerId(id);