~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to doc/html/qtimer.html

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="iso-8859-1"?>
 
2
<!DOCTYPE html
 
3
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
 
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 
5
<!-- /tmp/qt-4.0.0-espenr-1119621036935/qt-x11-opensource-desktop-4.0.0/src/corelib/kernel/qtimer.cpp -->
 
6
<head>
 
7
    <title>Qt 4.0: QTimer Class Reference</title>
 
8
    <style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
 
9
a:link { color: #004faf; text-decoration: none }
 
10
a:visited { color: #672967; text-decoration: none }
 
11
td.postheader { font-family: sans-serif }
 
12
tr.address { font-family: sans-serif }
 
13
body { background: #ffffff; color: black; }</style>
 
14
</head>
 
15
<body>
 
16
<table border="0" cellpadding="0" cellspacing="0" width="100%">
 
17
<tr>
 
18
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
 
19
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="annotated.html"><font color="#004faf">Annotated</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
 
20
<td align="right" valign="top" width="230"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></td></tr></table><h1 align="center">QTimer Class Reference</h1>
 
21
<p>The QTimer class provides repetitive and single-shot timers. <a href="#details">More...</a></p>
 
22
<pre>#include &lt;QTimer&gt;</pre><p>Part of the <a href="qtcore.html">QtCore</a> module.</p>
 
23
<p>Inherits <a href="qobject.html">QObject</a>.</p>
 
24
<ul>
 
25
<li><a href="qtimer-members.html">List of all members, including inherited members</a></li>
 
26
<li><a href="qtimer-qt3.html">Qt 3 support members</a></li>
 
27
</ul>
 
28
<a name="properties"></a>
 
29
<h3>Properties</h3>
 
30
<ul>
 
31
<li><div class="fn"/><b><a href="qtimer.html#interval-prop">interval</a></b> : int</li>
 
32
<li><div class="fn"/><b><a href="qtimer.html#singleShot-prop">singleShot</a></b> : bool</li>
 
33
</ul>
 
34
<ul>
 
35
<li><div class="fn"/>1 property inherited from <a href="qobject.html#properties">QObject</a></li>
 
36
</ul>
 
37
<a name="public-functions"></a>
 
38
<h3>Public Functions</h3>
 
39
<ul>
 
40
<li><div class="fn"/><b><a href="qtimer.html#QTimer">QTimer</a></b> ( QObject * <i>parent</i> = 0 )</li>
 
41
<li><div class="fn"/><b><a href="qtimer.html#dtor.QTimer">~QTimer</a></b> ()</li>
 
42
<li><div class="fn"/>int <b><a href="qtimer.html#interval-prop">interval</a></b> () const</li>
 
43
<li><div class="fn"/>bool <b><a href="qtimer.html#isActive">isActive</a></b> () const</li>
 
44
<li><div class="fn"/>bool <b><a href="qtimer.html#singleShot-prop">isSingleShot</a></b> () const</li>
 
45
<li><div class="fn"/>void <b><a href="qtimer.html#interval-prop">setInterval</a></b> ( int <i>msec</i> )</li>
 
46
<li><div class="fn"/>void <b><a href="qtimer.html#singleShot-prop">setSingleShot</a></b> ( bool <i>singleShot</i> )</li>
 
47
<li><div class="fn"/>int <b><a href="qtimer.html#timerId">timerId</a></b> () const</li>
 
48
</ul>
 
49
<ul>
 
50
<li><div class="fn"/>28 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
 
51
</ul>
 
52
<a name="public-slots"></a>
 
53
<h3>Public Slots</h3>
 
54
<ul>
 
55
<li><div class="fn"/>void <b><a href="qtimer.html#start">start</a></b> ( int <i>msec</i> )</li>
 
56
<li><div class="fn"/>void <b><a href="qtimer.html#start-2">start</a></b> ()</li>
 
57
<li><div class="fn"/>void <b><a href="qtimer.html#stop">stop</a></b> ()</li>
 
58
</ul>
 
59
<ul>
 
60
<li><div class="fn"/>1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
 
61
</ul>
 
62
<a name="signals"></a>
 
63
<h3>Signals</h3>
 
64
<ul>
 
65
<li><div class="fn"/>void <b><a href="qtimer.html#timeout">timeout</a></b> ()</li>
 
66
</ul>
 
67
<ul>
 
68
<li><div class="fn"/>1 signal inherited from <a href="qobject.html#signals">QObject</a></li>
 
69
</ul>
 
70
<a name="static-public-members"></a>
 
71
<h3>Static Public Members</h3>
 
72
<ul>
 
73
<li><div class="fn"/>void <b><a href="qtimer.html#singleShot">singleShot</a></b> ( int <i>msec</i>, QObject * <i>receiver</i>, const char * <i>member</i> )</li>
 
74
</ul>
 
75
<ul>
 
76
<li><div class="fn"/>4 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
 
77
</ul>
 
78
<h3>Additional Inherited Members</h3>
 
79
<ul>
 
80
<li><div class="fn"/>7 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
 
81
</ul>
 
82
<a name="details"></a>
 
83
<hr />
 
84
<h2>Detailed Description</h2>
 
85
<p>The QTimer class provides repetitive and single-shot timers.</p>
 
86
<p>The QTimer class provides a high-level programming interface for timers. To use it, create a QTimer, connect its <a href="qtimer.html#timeout">timeout</a>() signal to the appropriate slots, and call <a href="qtimer.html#start">start</a>(). From then on it will emit the <a href="qtimer.html#timeout">timeout</a>() signal at constant intervals.</p>
 
87
<p>Example for a one second (1000 millisecond) timer (from the <a href="widgets-analogclock.html">Analog Clock</a> example):</p>
 
88
<pre>&nbsp;       QTimer *timer = new QTimer(this);
 
89
        connect(timer, SIGNAL(timeout()), this, SLOT(update()));
 
90
        timer-&gt;start(1000);</pre>
 
91
<p>From then on, the <tt>update()</tt> slot is called every second.</p>
 
92
<p>You can set a timer to time out only once by calling setSingleShot(true). You can also use the static <a href="qtimer.html#singleShot">QTimer::singleShot</a>() function to call a slot after a specified interval:</p>
 
93
<pre>&nbsp;       QTimer::singleShot(200, this, SLOT(updateCaption()));</pre>
 
94
<p>As a special case, a QTimer with a timeout of 0 will time out as soon as all the events in the window system's event queue have been processed. This can be used to do heavy work while providing a snappy user interface:</p>
 
95
<pre>&nbsp;       QTimer *timer = new QTimer(this);
 
96
        connect(timer, SIGNAL(timeout()), this, SLOT(processOneThing()));
 
97
        timer-&gt;start();</pre>
 
98
<p><tt>processOneThing()</tt> will from then on be called repeatedly. It should be written in such a way that it always returns 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; multithreading is now becoming available on more and more platforms, and we expect that zero-milliseconds QTimers will gradually be replaced by <a href="qthread.html">QThread</a>s.</p>
 
99
<p>Note that QTimer's accuracy depends on the underlying operating system and hardware. Most platforms support an accuracy of 1 milliseconds, but Windows 95 and 98 support only 55. If Qt is unable to deliver the requested number of timer clicks, it will silently discard some.</p>
 
100
<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 inherit <a href="qobject.html">QObject</a>). The disadvantage is that <a href="qtimer.html#timerEvent">timerEvent</a>() does not support such high-level features as single-shot timers or signals.</p>
 
101
<p>Another alternative to using QTimer is to use <a href="qbasictimer.html">QBasicTimer</a>. It is typically less cumbersome than using <a href="qobject.html#startTimer">QObject::startTimer</a>() directly. See <a href="timers.html">Timers</a> for an overview of all three approaches.</p>
 
102
<p>Some operating systems limit the number of timers that may be used; Qt tries to work around these limitations.</p>
 
103
<p>See also <a href="qbasictimer.html">QBasicTimer</a>, <a href="qtimerevent.html">QTimerEvent</a>, <a href="qobject.html#timerEvent">QObject::timerEvent</a>(), and <a href="timers.html">Timers</a>.</p>
 
104
<hr />
 
105
<h2>Property Documentation</h2>
 
106
<h3 class="fn"><a name="interval-prop"></a>interval : int</h3>
 
107
<p>This property holds the timeout interval in milliseconds.</p>
 
108
<p>The default value for this property is 0. A <a href="qtimer.html">QTimer</a> with a timeout interval of 0 will time out as soon as all the events in the window system's event queue have been processed.</p>
 
109
<p>Setting the interval of an active timer changes its <a href="qtimer.html#timerId">timerId</a>().</p>
 
110
<p>Access functions:</p>
 
111
<ul>
 
112
<li><div class="fn"/><b>int interval () const</b></li>
 
113
<li><div class="fn"/><b>void setInterval ( int <i>msec</i> )</b></li>
 
114
</ul>
 
115
<p>See also <a href="qtimer.html#singleShot-prop">singleShot</a>.</p>
 
116
<h3 class="fn"><a name="singleShot-prop"></a>singleShot : bool</h3>
 
117
<p>This property holds whether the timer is a single-shot timer.</p>
 
118
<p>A single-shot timer fires only once, non-single-shot timers fire every <a href="qtimer.html#interval-prop">interval</a> milliseconds.</p>
 
119
<p>Access functions:</p>
 
120
<ul>
 
121
<li><div class="fn"/><b>bool isSingleShot () const</b></li>
 
122
<li><div class="fn"/><b>void setSingleShot ( bool <i>singleShot</i> )</b></li>
 
123
</ul>
 
124
<p>See also <a href="qtimer.html#interval-prop">interval</a> and <a href="qtimer.html#singleShot">singleShot</a>().</p>
 
125
<hr />
 
126
<h2>Member Function Documentation</h2>
 
127
<h3 class="fn"><a name="QTimer"></a>QTimer::QTimer ( <a href="qobject.html">QObject</a> * <i>parent</i> = 0 )</h3>
 
128
<p>Constructs a timer with the given <i>parent</i>.</p>
 
129
<h3 class="fn"><a name="dtor.QTimer"></a>QTimer::~QTimer ()</h3>
 
130
<p>Destroys the timer.</p>
 
131
<h3 class="fn"><a name="isActive"></a>bool QTimer::isActive () const</h3>
 
132
<p>Returns true if the timer is running (pending); otherwise returns false.</p>
 
133
<h3 class="fn"><a name="singleShot"></a>void QTimer::singleShot ( int <i>msec</i>, <a href="qobject.html">QObject</a> * <i>receiver</i>, const char * <i>member</i> )&nbsp;&nbsp;<tt> [static]</tt></h3>
 
134
<p>This static function calls a slot after a given time interval.</p>
 
135
<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 create a local <a href="qtimer.html">QTimer</a> object.</p>
 
136
<p>Example:</p>
 
137
<pre>&nbsp;   #include &lt;QApplication&gt;
 
138
    #include &lt;QTimer&gt;
 
139
 
 
140
    int main(int argc, char *argv[])
 
141
    {
 
142
        QApplication app(argc, argv);
 
143
        QTimer::singleShot(60000, &amp;app, SLOT(quit()));
 
144
        ...
 
145
        return app.exec();
 
146
    }</pre>
 
147
<p>This sample program automatically terminates after 10 minutes (600000 milliseconds).</p>
 
148
<p>The <i>receiver</i> is the receiving object and the <i>member</i> is the slot. The time interval is <i>msec</i> milliseconds.</p>
 
149
<p><b>Note:</b> This function is <a href="threads.html#reentrant">reentrant</a>.</p>
 
150
<p>See also <a href="qtimer.html#start">start</a>().</p>
 
151
<h3 class="fn"><a name="start"></a>void QTimer::start ( int <i>msec</i> )&nbsp;&nbsp;<tt> [slot]</tt></h3>
 
152
<p>Starts or restarts the timer with a timeout interval of <i>msec</i> milliseconds.</p>
 
153
<h3 class="fn"><a name="start-2"></a>void QTimer::start ()&nbsp;&nbsp;<tt> [slot]</tt></h3>
 
154
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
155
<p>Starts or restarts the timer with the timeout specified in <a href="qtimer.html#interval-prop">interval</a>.</p>
 
156
<p>If <a href="qtimer.html#singleShot-prop">singleShot</a> is true, the timer will be activated only once.</p>
 
157
<h3 class="fn"><a name="stop"></a>void QTimer::stop ()&nbsp;&nbsp;<tt> [slot]</tt></h3>
 
158
<p>Stops the timer.</p>
 
159
<p>See also <a href="qtimer.html#start">start</a>().</p>
 
160
<h3 class="fn"><a name="timeout"></a>void QTimer::timeout ()&nbsp;&nbsp;<tt> [signal]</tt></h3>
 
161
<p>This signal is emitted when the timer times out.</p>
 
162
<p>See also <a href="qtimer.html#interval-prop">interval</a>, <a href="qtimer.html#start">start</a>(), and <a href="qtimer.html#stop">stop</a>().</p>
 
163
<h3 class="fn"><a name="timerId"></a>int QTimer::timerId () const</h3>
 
164
<p>Returns the ID of the timer if the timer is running; otherwise returns -1.</p>
 
165
<p /><address><hr /><div align="center">
 
166
<table width="100%" cellspacing="0" border="0"><tr class="address">
 
167
<td width="30%">Copyright &copy; 2005 <a href="trolltech.html">Trolltech</a></td>
 
168
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
 
169
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
 
170
</tr></table></div></address></body>
 
171
</html>