source: trunk/src/corelib/kernel/qbasictimer.cpp@ 561

Last change on this file since 561 was 561, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.1 sources.

File size: 4.1 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtCore module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "qbasictimer.h"
43#include "qcoreapplication.h"
44#include "qabstracteventdispatcher.h"
45
46QT_BEGIN_NAMESPACE
47
48/*!
49 \class QBasicTimer
50 \brief The QBasicTimer class provides timer events for objects.
51
52 \ingroup events
53
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.
58
59 To use this class, create a QBasicTimer, and call its start()
60 function with a timeout interval and with a pointer to a QObject
61 subclass. When the timer times out it will send a timer event to
62 the QObject subclass. The timer can be stopped at any time using
63 stop(). isActive() returns true for a timer that is running;
64 i.e. it has been started, has not reached the timeout time, and
65 has not been stopped. The timer's ID can be retrieved using
66 timerId().
67
68 The \l{widgets/wiggly}{Wiggly} example uses QBasicTimer to repaint
69 a widget at regular intervals.
70
71 \sa QTimer, QTimerEvent, QObject::timerEvent(), Timers, {Wiggly Example}
72*/
73
74
75/*!
76 \fn QBasicTimer::QBasicTimer()
77
78 Contructs a basic timer.
79
80 \sa start()
81*/
82/*!
83 \fn QBasicTimer::~QBasicTimer()
84
85 Destroys the basic timer.
86*/
87
88/*!
89 \fn bool QBasicTimer::isActive() const
90
91 Returns true if the timer is running, has not yet timed
92 out, and has not been stopped; otherwise returns false.
93
94 \sa start() stop()
95*/
96
97/*!
98 \fn int QBasicTimer::timerId() const
99
100 Returns the timer's ID.
101
102 \sa QTimerEvent::timerId()
103*/
104
105/*!
106 \fn void QBasicTimer::start(int msec, QObject *object)
107
108 Starts (or restarts) the timer with a \a msec milliseconds
109 timeout.
110
111 The given \a object will receive timer events.
112
113 \sa stop() isActive() QObject::timerEvent()
114 */
115void QBasicTimer::start(int msec, QObject *obj)
116{
117 stop();
118 if (obj)
119 id = obj->startTimer(msec);
120}
121
122/*!
123 Stops the timer.
124
125 \sa start() isActive()
126*/
127void QBasicTimer::stop()
128{
129 if (id) {
130 QAbstractEventDispatcher *eventDispatcher = QAbstractEventDispatcher::instance();
131 if (eventDispatcher)
132 eventDispatcher->unregisterTimer(id);
133 }
134 id = 0;
135}
136
137QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.