summaryrefslogtreecommitdiffstats
path: root/doc/html/qtimer.html
blob: 1449f2d3d4c20df9b1e4c7eef4db14e9970c4177 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/kernel/qtimer.cpp:42 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>QTimer Class</title>
<style type="text/css"><!--
fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
 <a href="index.html">
<font color="#004faf">Home</font></a>
 | <a href="classes.html">
<font color="#004faf">All&nbsp;Classes</font></a>
 | <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
 | <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
 | <a href="groups.html">
<font color="#004faf">Grouped&nbsp;Classes</font></a>
 | <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QTimer Class Reference</h1>

<p>The QTimer class provides timer signals and single-shot timers.
<a href="#details">More...</a>
<p><tt>#include &lt;<a href="qtimer-h.html">qtimer.h</a>&gt;</tt>
<p>Inherits <a href="qobject.html">QObject</a>.
<p><a href="qtimer-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li class=fn><a href="#QTimer"><b>QTimer</b></a> ( QObject&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0 )</li>
<li class=fn><a href="#~QTimer"><b>~QTimer</b></a> ()</li>
<li class=fn>bool <a href="#isActive"><b>isActive</b></a> () const</li>
<li class=fn>int <a href="#start"><b>start</b></a> ( int&nbsp;msec, bool&nbsp;sshot = FALSE )</li>
<li class=fn>void <a href="#changeInterval"><b>changeInterval</b></a> ( int&nbsp;msec )</li>
<li class=fn>void <a href="#stop"><b>stop</b></a> ()</li>
<li class=fn>int <a href="#timerId"><b>timerId</b></a> () const</li>
</ul>
<h2>Signals</h2>
<ul>
<li class=fn>void <a href="#timeout"><b>timeout</b></a> ()</li>
</ul>
<h2>Static Public Members</h2>
<ul>
<li class=fn>void <a href="#singleShot"><b>singleShot</b></a> ( int&nbsp;msec, QObject&nbsp;*&nbsp;receiver, const&nbsp;char&nbsp;*&nbsp;member )</li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>


The QTimer class provides timer signals and single-shot timers.
<p> 


<p> It uses <a href="qtimerevent.html">timer events</a> internally to
provide a more versatile timer. QTimer is very easy to use:
create a QTimer, call <a href="#start">start</a>() to start it and connect its
<a href="#timeout">timeout</a>() to the appropriate slots. When the time is up it will
emit the timeout() signal.
<p> Note that a QTimer object is destroyed automatically when its
parent object is destroyed.
<p> Example:
<pre>
        QTimer *timer = new QTimer( myObject );
        <a href="qobject.html#connect">connect</a>( timer, SIGNAL(<a href="#timeout">timeout</a>()), myObject, SLOT(timerDone()) );
        timer-&gt;<a href="#start">start</a>( 2000, TRUE ); // 2 seconds single-shot timer
    </pre>
 
<p> You can also use the static <a href="#singleShot">singleShot</a>() function to create a
single shot timer.
<p> As a special case, a QTimer with timeout 0 times out as soon as
all the events in the window system's event queue have been
processed.
<p> This can be used to do heavy work while providing a snappy
user interface:
<pre>
        QTimer *t = new QTimer( myObject );
        <a href="qobject.html#connect">connect</a>( t, SIGNAL(<a href="#timeout">timeout</a>()), SLOT(processOneThing()) );
        t-&gt;<a href="#start">start</a>( 0, FALSE );
    </pre>
 
<p> myObject->processOneThing() will be called repeatedly and should
return quickly (typically after processing one data item) so that
Qt can deliver events to widgets and stop the timer as soon as it
has done all its work. This is the traditional way of
implementing heavy work in GUI applications; multi-threading is
now becoming available on more and more platforms, and we expect
that null events will eventually be replaced by threading.
<p> Note that QTimer's accuracy depends on the underlying operating
system and hardware. Most platforms support an accuracy of 20ms;
some provide more. If Qt is unable to deliver the requested
number of timer clicks, it will silently discard some.
<p> An alternative to using QTimer is to call <a href="qobject.html#startTimer">QObject::startTimer</a>()
for your object and reimplement the <a href="qobject.html#timerEvent">QObject::timerEvent</a>() event
handler in your class (which must, of course, inherit <a href="qobject.html">QObject</a>).
The disadvantage is that <a href="qobject.html#timerEvent">timerEvent</a>() does not support such
high-level features as single-shot timers or signals.
<p> Some operating systems limit the number of timers that may be
used; Qt tries to work around these limitations.
<p>See also <a href="events.html">Event Classes</a> and <a href="time.html">Time and Date</a>.

<hr><h2>Member Function Documentation</h2>
<h3 class=fn><a name="QTimer"></a>QTimer::QTimer ( <a href="qobject.html">QObject</a>&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0 )
</h3>
Constructs a timer called <em>name</em>, with the parent <em>parent</em>.
<p> Note that the parent object's destructor will destroy this timer
object.

<h3 class=fn><a name="~QTimer"></a>QTimer::~QTimer ()
</h3>
Destroys the timer.

<h3 class=fn>void <a name="changeInterval"></a>QTimer::changeInterval ( int&nbsp;msec )
</h3>
Changes the timeout interval to <em>msec</em> milliseconds.
<p> If the timer signal is pending, it will be stopped and restarted;
otherwise it will be started.
<p> <p>See also <a href="#start">start</a>() and <a href="#isActive">isActive</a>().

<h3 class=fn>bool <a name="isActive"></a>QTimer::isActive () const
</h3>

<p> Returns TRUE if the timer is running (pending); otherwise returns
FALSE.

<p>Example: <a href="tutorial1-11.html#x2376">t11/cannon.cpp</a>.
<h3 class=fn>void <a name="singleShot"></a>QTimer::singleShot ( int&nbsp;msec, <a href="qobject.html">QObject</a>&nbsp;*&nbsp;receiver, const&nbsp;char&nbsp;*&nbsp;member )<tt> [static]</tt>
</h3>
This static function calls a slot after a given time interval.
<p> It is very convenient to use this function because you do not need
to bother with a <a href="qobject.html#timerEvent">timerEvent</a> or
to create a local QTimer object.
<p> Example:
<pre>
        #include &lt;<a href="qapplication-h.html">qapplication.h</a>&gt;
        #include &lt;<a href="qtimer-h.html">qtimer.h</a>&gt;

        int main( int argc, char **argv )
        {
            <a href="qapplication.html">QApplication</a> a( argc, argv );
            QTimer::<a href="#singleShot">singleShot</a>( 10*60*1000, &amp;a, SLOT(<a href="qapplication.html#quit">quit</a>()) );
                ... // create and show your widgets
            return a.<a href="qapplication.html#exec">exec</a>();
        }
    </pre>
 
<p> This sample program automatically terminates after 10 minutes (i.e.
600000 milliseconds).
<p> The <em>receiver</em> is the receiving object and the <em>member</em> is the
slot. The time interval is <em>msec</em>.

<h3 class=fn>int <a name="start"></a>QTimer::start ( int&nbsp;msec, bool&nbsp;sshot = FALSE )
</h3>
Starts the timer with a <em>msec</em> milliseconds timeout, and returns
the ID of the timer, or zero when starting the timer failed.
<p> If <em>sshot</em> is TRUE, the timer will be activated only once;
otherwise it will continue until it is stopped.
<p> Any pending timer will be stopped.
<p> <p>See also <a href="#singleShot">singleShot</a>(), <a href="#stop">stop</a>(), <a href="#changeInterval">changeInterval</a>(), and <a href="#isActive">isActive</a>().

<p>Examples: <a href="aclock-example.html#x1204">aclock/aclock.cpp</a>, <a href="dirview-example.html#x1704">dirview/dirview.cpp</a>, <a href="distributor-example.html#x2671">distributor/distributor.ui.h</a>, <a href="forever-example.html#x1053">forever/forever.cpp</a>, <a href="hello-example.html#x1639">hello/hello.cpp</a>, <a href="tutorial1-11.html#x2377">t11/cannon.cpp</a>, and <a href="tutorial1-13.html#x2407">t13/cannon.cpp</a>.
<h3 class=fn>void <a name="stop"></a>QTimer::stop ()
</h3>
Stops the timer.
<p> <p>See also <a href="#start">start</a>().

<p>Examples: <a href="dirview-example.html#x1705">dirview/dirview.cpp</a>, <a href="tutorial1-11.html#x2378">t11/cannon.cpp</a>, <a href="tutorial1-12.html#x2400">t12/cannon.cpp</a>, and <a href="tutorial1-13.html#x2408">t13/cannon.cpp</a>.
<h3 class=fn>void <a name="timeout"></a>QTimer::timeout ()<tt> [signal]</tt>
</h3>

<p> This signal is emitted when the timer is activated.

<p>Examples: <a href="aclock-example.html#x1205">aclock/aclock.cpp</a>, <a href="dirview-example.html#x1706">dirview/dirview.cpp</a>, <a href="distributor-example.html#x2672">distributor/distributor.ui.h</a>, <a href="forever-example.html#x1054">forever/forever.cpp</a>, <a href="hello-example.html#x1640">hello/hello.cpp</a>, and <a href="tutorial1-11.html#x2379">t11/cannon.cpp</a>.
<h3 class=fn>int <a name="timerId"></a>QTimer::timerId () const
</h3>

<p> Returns the ID of the timer if the timer is running; otherwise returns
-1.

<!-- eof -->
<hr><p>
This file is part of the <a href="index.html">Qt toolkit</a>.
Copyright &copy; 1995-2007
<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright &copy; 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>Qt 3.3.8</div>
</table></div></address></body>
</html>