File: qtimer.html

package info (click to toggle)
qt-embedded 2.3.2-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 68,608 kB
  • ctags: 45,998
  • sloc: cpp: 276,654; ansic: 71,987; makefile: 29,074; sh: 12,305; yacc: 2,465; python: 1,863; perl: 481; lex: 480; xml: 68; lisp: 15
file content (154 lines) | stat: -rw-r--r-- 8,241 bytes parent folder | download
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Qt Toolkit - QTimer Class</title><style type="text/css"><!--
h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }body { background: white; color: black; }
--></style>
</head><body bgcolor="#ffffff">

<table width="100%">
<tr><td><a href="index.html">
<img width="100" height="100" src="qtlogo.png"
alt="Home" border="0"><img width="100"
height="100" src="face.png" alt="Home" border="0">
</a><td valign=top><div align=right><img src="dochead.png" width="472" height="27"><br>
<a href="classes.html"><b>Classes</b></a>
-<a href="annotated.html">Annotated</a>
- <a href="hierarchy.html">Tree</a>
-<a href="functions.html">Functions</a>
-<a href="index.html">Home</a>
-<a href="topicals.html"><b>Structure</b></a>
</div>
</table>

<h1 align=center>QTimer Class Reference</h1><br clear="all">
<p>
The QTimer class provides timer signals and single-shot timers.
<a href="#details">More...</a>
<p>
<code>#include &lt;<a href="qtimer-h.html">qtimer.h</a>&gt;</code>
<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><div class="fn"><a href="#86dd7a"><b>QTimer</b></a>(QObject*parent=0, constchar*name=0)</div>
<li><div class="fn"><a href="#d930f1"><b>~QTimer</b></a>()</div>
<li><div class="fn">bool<a href="#0abb5f"><b>isActive</b></a>()const</div>
<li><div class="fn">int<a href="#ce33bc"><b>start</b></a>(intmsec, boolsshot=FALSE)</div>
<li><div class="fn">void<a href="#9f2d6d"><b>changeInterval</b></a>(intmsec)</div>
<li><div class="fn">void<a href="#7ad213"><b>stop</b></a>()</div>
</ul>
<h2>Signals</h2>
<ul>
<li><div class="fn">void<a href="#66bd1b"><b>timeout</b></a>()</div>
</ul>
<h2>Static Public Members</h2>
<ul>
<li><div class="fn">void<a href="#f2ac71"><b>singleShot</b></a>(intmsec, QObject*receiver, constchar*member)</div>
</ul>
<hr><h2><a name="details"></a>Detailed Description</h2>
The QTimer class provides timer signals and single-shot timers.
<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="#ce33bc">start</a>() to start it and connect its <a href="#66bd1b">timeout</a>() to the appropriate slots,
then when the time is up it will emit timeout().
<p>Note that a QTimer object is destroyed automatically when its parent
object is destroyed.
<p>Example:
<pre>    <a href="qtimer.html">QTimer</a> *timer = new <a href="qtimer.html">QTimer</a>( myObject );
    connect( timer, SIGNAL(timeout()),
             myObject, SLOT(timerDone()) );
    timer-&gt;<a href="#ce33bc">start</a>( 2000, TRUE );                 // 2 seconds single-shot
</pre>
<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>    <a href="qtimer.html">QTimer</a> *t = new <a href="qtimer.html">QTimer</a>( myObject );
    connect( t, SIGNAL(timeout()), SLOT(processOneThing()) );
    t-&gt;<a href="#ce33bc">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#4c6b67">QObject::startTimer</a>() for
your object and reimplement the <a href="qobject.html#7fd5bf">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#7fd5bf">timerEvent</a>() does not support such high-level
features as single-shot timers or signals.
<p>Examples:
 <a href="forever-forever-cpp.html#QTimer">forever/forever.cpp</a>

<hr><h2>Member Function Documentation</h2>
<h3 class="fn"><a name="86dd7a"></a>QTimer::QTimer(<a href="qobject.html">QObject</a>*parent=0, constchar*name=0)</h3>
<p>Constructs a timer with a <em>parent</em> and a <em>name.</em>
<p>Notice that the destructor of the parent object will destroy this timer
object.
<h3 class="fn"><a name="d930f1"></a>QTimer::~QTimer()</h3>
<p>Destructs the timer.
<h3 class="fn">void<a name="9f2d6d"></a>QTimer::changeInterval(intmsec)</h3>
<p>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>See also  <a href="#ce33bc">start</a>() and <a href="#0abb5f">isActive</a>().
<h3 class="fn">bool<a name="180c8a"></a>QTimer::event(<a href="qevent.html">QEvent</a>*e) <code>[virtualprotected]</code></h3>
<p>Reimplemented for internal reasons; the API is not affected.
<p>Reimplemented from <a href="qobject.html#c67adb">QObject.</a>
<h3 class="fn">bool<a name="0abb5f"></a>QTimer::isActive()const</h3>
<p>Returns TRUE if the timer is running (pending), or FALSE is the timer is
idle.
<h3 class="fn">void<a name="f2ac71"></a>QTimer::singleShot(intmsec, <a href="qobject.html">QObject</a>*receiver, constchar*member) <code>[static]</code></h3>
<p>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#7fd5bf">timerEvent</a> or to
create a local QTimer object.
<p>Example:
<pre>    #include &lt;qapplication.h&gt;
    #include &lt;qtimer.h&gt;

    int main( int argc, char **argv )
    {
        <a href="qapplication.html">QApplication</a> a( argc, argv );
        <a href="#f2ac71">QTimer::singleShot</a>( 10*60*1000, &amp;a, SLOT(quit()) );
            ... // create and show your widgets
        return a.<a href="qapplication.html#84c7bf">exec</a>();
    }
</pre>
<p>This sample program automatically terminates after 10 minutes (i.e.
600000 milliseconds).
<h3 class="fn">int<a name="ce33bc"></a>QTimer::start(intmsec, boolsshot=FALSE)</h3>
<p>Starts the timer with a <em>msecs</em> milliseconds timeout.
<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>See also  <a href="#7ad213">stop</a>(), <a href="#9f2d6d">changeInterval</a>() and <a href="#0abb5f">isActive</a>().
<p>Examples:
 <a href="forever-forever-cpp.html#start">forever/forever.cpp</a>
<h3 class="fn">void<a name="7ad213"></a>QTimer::stop()</h3>
<p>Stops the timer.
<p>See also  <a href="#ce33bc">start</a>().
<h3 class="fn">void<a name="66bd1b"></a>QTimer::timeout() <code>[signal]</code></h3>
<p>This signal is emitted when the timer is activated.
<hr><p>
Search the documentation, FAQ, qt-interest archive and more (uses
<a href="http://www.trolltech.com">www.trolltech.com</a>):<br>
<form method=post action="http://www.trolltech.com/search.cgi">
<input type=hidden name="version" value="2.3.2"><nobr>
<input size="50" name="search"><input type=submit value="Search">
</nobr></form><hr><p>
This file is part of the <a href="index.html">Qt toolkit</a>,
copyright &copy; 1995-2001
<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  2001 Trolltech<td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a>
<td align="right"><div align="right">Qt version 2.3.2</div>
</table></div></address></body></html>