summaryrefslogtreecommitdiffstats
path: root/doc/html/ntqtimer.html
blob: b67890351f0b21d3c5e6380cea102f3dd0c2c417 (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>TQTimer 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>TQTimer Class Reference</h1>

<p>The TQTimer class provides timer signals and single-shot timers.
<a href="#details">More...</a>
<p><tt>#include &lt;<a href="qtimer-h.html">ntqtimer.h</a>&gt;</tt>
<p>Inherits <a href="ntqobject.html">TQObject</a>.
<p><a href="qtimer-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li class=fn><a href="#TQTimer"><b>TQTimer</b></a> ( TQObject&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0 )</li>
<li class=fn><a href="#~TQTimer"><b>~TQTimer</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, TQObject&nbsp;*&nbsp;receiver, const&nbsp;char&nbsp;*&nbsp;member )</li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>


The TQTimer 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. TQTimer is very easy to use:
create a TQTimer, 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 TQTimer object is destroyed automatically when its
parent object is destroyed.
<p> Example:
<pre>
        TQTimer *timer = new TQTimer( myObject );
        <a href="ntqobject.html#connect">connect</a>( timer, TQ_SIGNAL(<a href="#timeout">timeout</a>()), myObject, TQ_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 TQTimer 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>
        TQTimer *t = new TQTimer( myObject );
        <a href="ntqobject.html#connect">connect</a>( t, TQ_SIGNAL(<a href="#timeout">timeout</a>()), TQ_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
TQt 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 TQTimer's accuracy depends on the underlying operating
system and hardware. Most platforms support an accuracy of 20ms;
some provide more. If TQt is unable to deliver the requested
number of timer clicks, it will silently discard some.
<p> An alternative to using TQTimer is to call <a href="ntqobject.html#startTimer">TQObject::startTimer</a>()
for your object and reimplement the <a href="ntqobject.html#timerEvent">TQObject::timerEvent</a>() event
handler in your class (which must, of course, inherit <a href="ntqobject.html">TQObject</a>).
The disadvantage is that <a href="ntqobject.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; TQt 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="TQTimer"></a>TQTimer::TQTimer ( <a href="ntqobject.html">TQObject</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="~TQTimer"></a>TQTimer::~TQTimer ()
</h3>
Destroys the timer.

<h3 class=fn>void <a name="changeInterval"></a>TQTimer::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>TQTimer::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>TQTimer::singleShot ( int&nbsp;msec, <a href="ntqobject.html">TQObject</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="ntqobject.html#timerEvent">timerEvent</a> or
to create a local TQTimer object.
<p> Example:
<pre>
        #include &lt;<a href="qapplication-h.html">ntqapplication.h</a>&gt;
        #include &lt;<a href="qtimer-h.html">ntqtimer.h</a>&gt;

        int main( int argc, char **argv )
        {
            <a href="ntqapplication.html">TQApplication</a> a( argc, argv );
            TQTimer::<a href="#singleShot">singleShot</a>( 10*60*1000, &amp;a, TQ_SLOT(<a href="ntqapplication.html#quit">quit</a>()) );
                ... // create and show your widgets
            return a.<a href="ntqapplication.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>TQTimer::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>TQTimer::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>TQTimer::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>TQTimer::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">TQt 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>TQt 3.3.8</div>
</table></div></address></body>
</html>