source: trunk/doc/html/qtimer.html@ 190

Last change on this file since 190 was 190, checked in by rudi, 14 years ago

reference documentation added

File size: 9.9 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/kernel/qtimer.cpp:42 -->
3<html>
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6<title>QTimer Class</title>
7<style type="text/css"><!--
8fn { margin-left: 1cm; text-indent: -1cm; }
9a:link { color: #004faf; text-decoration: none }
10a:visited { color: #672967; text-decoration: none }
11body { background: #ffffff; color: black; }
12--></style>
13</head>
14<body>
15
16<table border="0" cellpadding="0" cellspacing="0" width="100%">
17<tr bgcolor="#E5E5E5">
18<td valign=center>
19 <a href="index.html">
20<font color="#004faf">Home</font></a>
21 | <a href="classes.html">
22<font color="#004faf">All&nbsp;Classes</font></a>
23 | <a href="mainclasses.html">
24<font color="#004faf">Main&nbsp;Classes</font></a>
25 | <a href="annotated.html">
26<font color="#004faf">Annotated</font></a>
27 | <a href="groups.html">
28<font color="#004faf">Grouped&nbsp;Classes</font></a>
29 | <a href="functions.html">
30<font color="#004faf">Functions</font></a>
31</td>
32<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>
33
34<p>The QTimer class provides timer signals and single-shot timers.
35<a href="#details">More...</a>
36<p><tt>#include &lt;<a href="qtimer-h.html">qtimer.h</a>&gt;</tt>
37<p>Inherits <a href="qobject.html">QObject</a>.
38<p><a href="qtimer-members.html">List of all member functions.</a>
39<h2>Public Members</h2>
40<ul>
41<li class=fn><a href="#QTimer"><b>QTimer</b></a> ( QObject&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0 )</li>
42<li class=fn><a href="#~QTimer"><b>~QTimer</b></a> ()</li>
43<li class=fn>bool <a href="#isActive"><b>isActive</b></a> () const</li>
44<li class=fn>int <a href="#start"><b>start</b></a> ( int&nbsp;msec, bool&nbsp;sshot = FALSE )</li>
45<li class=fn>void <a href="#changeInterval"><b>changeInterval</b></a> ( int&nbsp;msec )</li>
46<li class=fn>void <a href="#stop"><b>stop</b></a> ()</li>
47<li class=fn>int <a href="#timerId"><b>timerId</b></a> () const</li>
48</ul>
49<h2>Signals</h2>
50<ul>
51<li class=fn>void <a href="#timeout"><b>timeout</b></a> ()</li>
52</ul>
53<h2>Static Public Members</h2>
54<ul>
55<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>
56</ul>
57<hr><a name="details"></a><h2>Detailed Description</h2>
58
59
60The QTimer class provides timer signals and single-shot timers.
61<p>
62
63
64<p> It uses <a href="qtimerevent.html">timer events</a> internally to
65provide a more versatile timer. QTimer is very easy to use:
66create a QTimer, call <a href="#start">start</a>() to start it and connect its
67<a href="#timeout">timeout</a>() to the appropriate slots. When the time is up it will
68emit the timeout() signal.
69<p> Note that a QTimer object is destroyed automatically when its
70parent object is destroyed.
71<p> Example:
72<pre>
73 QTimer *timer = new QTimer( myObject );
74 <a href="qobject.html#connect">connect</a>( timer, SIGNAL(<a href="#timeout">timeout</a>()), myObject, SLOT(timerDone()) );
75 timer-&gt;<a href="#start">start</a>( 2000, TRUE ); // 2 seconds single-shot timer
76 </pre>
77
78<p> You can also use the static <a href="#singleShot">singleShot</a>() function to create a
79single shot timer.
80<p> As a special case, a QTimer with timeout 0 times out as soon as
81all the events in the window system's event queue have been
82processed.
83<p> This can be used to do heavy work while providing a snappy
84user interface:
85<pre>
86 QTimer *t = new QTimer( myObject );
87 <a href="qobject.html#connect">connect</a>( t, SIGNAL(<a href="#timeout">timeout</a>()), SLOT(processOneThing()) );
88 t-&gt;<a href="#start">start</a>( 0, FALSE );
89 </pre>
90
91<p> myObject->processOneThing() will be called repeatedly and should
92return quickly (typically after processing one data item) so that
93Qt can deliver events to widgets and stop the timer as soon as it
94has done all its work. This is the traditional way of
95implementing heavy work in GUI applications; multi-threading is
96now becoming available on more and more platforms, and we expect
97that null events will eventually be replaced by threading.
98<p> Note that QTimer's accuracy depends on the underlying operating
99system and hardware. Most platforms support an accuracy of 20ms;
100some provide more. If Qt is unable to deliver the requested
101number of timer clicks, it will silently discard some.
102<p> An alternative to using QTimer is to call <a href="qobject.html#startTimer">QObject::startTimer</a>()
103for your object and reimplement the <a href="qobject.html#timerEvent">QObject::timerEvent</a>() event
104handler in your class (which must, of course, inherit <a href="qobject.html">QObject</a>).
105The disadvantage is that <a href="qobject.html#timerEvent">timerEvent</a>() does not support such
106high-level features as single-shot timers or signals.
107<p> Some operating systems limit the number of timers that may be
108used; Qt tries to work around these limitations.
109<p>See also <a href="events.html">Event Classes</a> and <a href="time.html">Time and Date</a>.
110
111<hr><h2>Member Function Documentation</h2>
112<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 )
113</h3>
114Constructs a timer called <em>name</em>, with the parent <em>parent</em>.
115<p> Note that the parent object's destructor will destroy this timer
116object.
117
118<h3 class=fn><a name="~QTimer"></a>QTimer::~QTimer ()
119</h3>
120Destroys the timer.
121
122<h3 class=fn>void <a name="changeInterval"></a>QTimer::changeInterval ( int&nbsp;msec )
123</h3>
124Changes the timeout interval to <em>msec</em> milliseconds.
125<p> If the timer signal is pending, it will be stopped and restarted;
126otherwise it will be started.
127<p> <p>See also <a href="#start">start</a>() and <a href="#isActive">isActive</a>().
128
129<h3 class=fn>bool <a name="isActive"></a>QTimer::isActive () const
130</h3>
131
132<p> Returns TRUE if the timer is running (pending); otherwise returns
133FALSE.
134
135<p>Example: <a href="tutorial1-11.html#x2376">t11/cannon.cpp</a>.
136<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>
137</h3>
138This static function calls a slot after a given time interval.
139<p> It is very convenient to use this function because you do not need
140to bother with a <a href="qobject.html#timerEvent">timerEvent</a> or
141to create a local QTimer object.
142<p> Example:
143<pre>
144 #include &lt;<a href="qapplication-h.html">qapplication.h</a>&gt;
145 #include &lt;<a href="qtimer-h.html">qtimer.h</a>&gt;
146
147 int main( int argc, char **argv )
148 {
149 <a href="qapplication.html">QApplication</a> a( argc, argv );
150 QTimer::<a href="#singleShot">singleShot</a>( 10*60*1000, &amp;a, SLOT(<a href="qapplication.html#quit">quit</a>()) );
151 ... // create and show your widgets
152 return a.<a href="qapplication.html#exec">exec</a>();
153 }
154 </pre>
155
156<p> This sample program automatically terminates after 10 minutes (i.e.
157600000 milliseconds).
158<p> The <em>receiver</em> is the receiving object and the <em>member</em> is the
159slot. The time interval is <em>msec</em>.
160
161<h3 class=fn>int <a name="start"></a>QTimer::start ( int&nbsp;msec, bool&nbsp;sshot = FALSE )
162</h3>
163Starts the timer with a <em>msec</em> milliseconds timeout, and returns
164the ID of the timer, or zero when starting the timer failed.
165<p> If <em>sshot</em> is TRUE, the timer will be activated only once;
166otherwise it will continue until it is stopped.
167<p> Any pending timer will be stopped.
168<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>().
169
170<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>.
171<h3 class=fn>void <a name="stop"></a>QTimer::stop ()
172</h3>
173Stops the timer.
174<p> <p>See also <a href="#start">start</a>().
175
176<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>.
177<h3 class=fn>void <a name="timeout"></a>QTimer::timeout ()<tt> [signal]</tt>
178</h3>
179
180<p> This signal is emitted when the timer is activated.
181
182<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>.
183<h3 class=fn>int <a name="timerId"></a>QTimer::timerId () const
184</h3>
185
186<p> Returns the ID of the timer if the timer is running; otherwise returns
187-1.
188
189<!-- eof -->
190<hr><p>
191This file is part of the <a href="index.html">Qt toolkit</a>.
192Copyright &copy; 1995-2007
193<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
194<table width=100% cellspacing=0 border=0><tr>
195<td>Copyright &copy; 2007
196<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
197<td align=right><div align=right>Qt 3.3.8</div>
198</table></div></address></body>
199</html>
Note: See TracBrowser for help on using the repository browser.