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

Last change on this file since 385 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 4.1 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtCore module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** 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 are unsure which license is appropriate for your use, please
37** contact the sales department 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 time
53 \ingroup events
54
55 This is a fast, lightweight, and low-level class used by Qt
56 internally. We recommend using the higher-level QTimer class
57 rather than this class if you want to use timers in your
58 applications.
59
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
67 timerId().
68
69 The \l{widgets/wiggly}{Wiggly} example uses QBasicTimer to repaint
70 a widget at regular intervals.
71
72 \sa QTimer, QTimerEvent, QObject::timerEvent(), Timers, {Wiggly Example}
73*/
74
75
76/*!
77 \fn QBasicTimer::QBasicTimer()
78
79 Contructs a basic timer.
80
81 \sa start()
82*/
83/*!
84 \fn QBasicTimer::~QBasicTimer()
85
86 Destroys the basic timer.
87*/
88
89/*!
90 \fn bool QBasicTimer::isActive() const
91
92 Returns true if the timer is running, has not yet timed
93 out, and has not been stopped; otherwise returns false.
94
95 \sa start() stop()
96*/
97
98/*!
99 \fn int QBasicTimer::timerId() const
100
101 Returns the timer's ID.
102
103 \sa QTimerEvent::timerId()
104*/
105
106/*!
107 \fn void QBasicTimer::start(int msec, QObject *object)
108
109 Starts (or restarts) the timer with a \a msec milliseconds
110 timeout.
111
112 The given \a object will receive timer events.
113
114 \sa stop() isActive() QObject::timerEvent()
115 */
116void QBasicTimer::start(int msec, QObject *obj)
117{
118 stop();
119 if (obj)
120 id = obj->startTimer(msec);
121}
122
123/*!
124 Stops the timer.
125
126 \sa start() isActive()
127*/
128void QBasicTimer::stop()
129{
130 if (id) {
131 QAbstractEventDispatcher *eventDispatcher = QAbstractEventDispatcher::instance();
132 if (eventDispatcher)
133 eventDispatcher->unregisterTimer(id);
134 }
135 id = 0;
136}
137
138QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.