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"><!--
|
---|
8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
9 | a:link { color: #004faf; text-decoration: none }
|
---|
10 | a:visited { color: #672967; text-decoration: none }
|
---|
11 | body { 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 Classes</font></a>
|
---|
23 | | <a href="mainclasses.html">
|
---|
24 | <font color="#004faf">Main 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 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 <<a href="qtimer-h.html">qtimer.h</a>></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 * parent = 0, const char * 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 msec, bool sshot = FALSE )</li>
|
---|
45 | <li class=fn>void <a href="#changeInterval"><b>changeInterval</b></a> ( int 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 msec, QObject * receiver, const char * member )</li>
|
---|
56 | </ul>
|
---|
57 | <hr><a name="details"></a><h2>Detailed Description</h2>
|
---|
58 |
|
---|
59 |
|
---|
60 | The 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
|
---|
65 | provide a more versatile timer. QTimer is very easy to use:
|
---|
66 | create 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
|
---|
68 | emit the timeout() signal.
|
---|
69 | <p> Note that a QTimer object is destroyed automatically when its
|
---|
70 | parent 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-><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
|
---|
79 | single shot timer.
|
---|
80 | <p> As a special case, a QTimer with timeout 0 times out as soon as
|
---|
81 | all the events in the window system's event queue have been
|
---|
82 | processed.
|
---|
83 | <p> This can be used to do heavy work while providing a snappy
|
---|
84 | user 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-><a href="#start">start</a>( 0, FALSE );
|
---|
89 | </pre>
|
---|
90 |
|
---|
91 | <p> myObject->processOneThing() will be called repeatedly and should
|
---|
92 | return quickly (typically after processing one data item) so that
|
---|
93 | Qt can deliver events to widgets and stop the timer as soon as it
|
---|
94 | has done all its work. This is the traditional way of
|
---|
95 | implementing heavy work in GUI applications; multi-threading is
|
---|
96 | now becoming available on more and more platforms, and we expect
|
---|
97 | that null events will eventually be replaced by threading.
|
---|
98 | <p> Note that QTimer's accuracy depends on the underlying operating
|
---|
99 | system and hardware. Most platforms support an accuracy of 20ms;
|
---|
100 | some provide more. If Qt is unable to deliver the requested
|
---|
101 | number 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>()
|
---|
103 | for your object and reimplement the <a href="qobject.html#timerEvent">QObject::timerEvent</a>() event
|
---|
104 | handler in your class (which must, of course, inherit <a href="qobject.html">QObject</a>).
|
---|
105 | The disadvantage is that <a href="qobject.html#timerEvent">timerEvent</a>() does not support such
|
---|
106 | high-level features as single-shot timers or signals.
|
---|
107 | <p> Some operating systems limit the number of timers that may be
|
---|
108 | used; 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> * parent = 0, const char * name = 0 )
|
---|
113 | </h3>
|
---|
114 | Constructs 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
|
---|
116 | object.
|
---|
117 |
|
---|
118 | <h3 class=fn><a name="~QTimer"></a>QTimer::~QTimer ()
|
---|
119 | </h3>
|
---|
120 | Destroys the timer.
|
---|
121 |
|
---|
122 | <h3 class=fn>void <a name="changeInterval"></a>QTimer::changeInterval ( int msec )
|
---|
123 | </h3>
|
---|
124 | Changes the timeout interval to <em>msec</em> milliseconds.
|
---|
125 | <p> If the timer signal is pending, it will be stopped and restarted;
|
---|
126 | otherwise 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
|
---|
133 | FALSE.
|
---|
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 msec, <a href="qobject.html">QObject</a> * receiver, const char * member )<tt> [static]</tt>
|
---|
137 | </h3>
|
---|
138 | This 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
|
---|
140 | to bother with a <a href="qobject.html#timerEvent">timerEvent</a> or
|
---|
141 | to create a local QTimer object.
|
---|
142 | <p> Example:
|
---|
143 | <pre>
|
---|
144 | #include <<a href="qapplication-h.html">qapplication.h</a>>
|
---|
145 | #include <<a href="qtimer-h.html">qtimer.h</a>>
|
---|
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, &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.
|
---|
157 | 600000 milliseconds).
|
---|
158 | <p> The <em>receiver</em> is the receiving object and the <em>member</em> is the
|
---|
159 | slot. The time interval is <em>msec</em>.
|
---|
160 |
|
---|
161 | <h3 class=fn>int <a name="start"></a>QTimer::start ( int msec, bool sshot = FALSE )
|
---|
162 | </h3>
|
---|
163 | Starts the timer with a <em>msec</em> milliseconds timeout, and returns
|
---|
164 | the 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;
|
---|
166 | otherwise 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>
|
---|
173 | Stops 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>
|
---|
191 | This file is part of the <a href="index.html">Qt toolkit</a>.
|
---|
192 | Copyright © 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 © 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>
|
---|