1QTimer(3qt) QTimer(3qt)
2
3
4
6 QTimer - Timer signals and single-shot timers
7
9 #include <qtimer.h>
10
11 Inherits QObject.
12
13 Public Members
14 QTimer ( QObject * parent = 0, const char * name = 0 )
15 ~QTimer ()
16 bool isActive () const
17 int start ( int msec, bool sshot = FALSE )
18 void changeInterval ( int msec )
19 void stop ()
20 int timerId () const
21
22 Signals
23 void timeout ()
24
25 Static Public Members
26 void singleShot ( int msec, QObject * receiver, const char * member )
27
29 The QTimer class provides timer signals and single-shot timers.
30
31 It uses timer events internally to provide a more versatile timer.
32 QTimer is very easy to use: create a QTimer, call start() to start it
33 and connect its timeout() to the appropriate slots. When the time is up
34 it will emit the timeout() signal.
35
36 Note that a QTimer object is destroyed automatically when its parent
37 object is destroyed.
38
39 Example:
40
41 QTimer *timer = new QTimer( myObject );
42 connect( timer, SIGNAL(timeout()), myObject, SLOT(timerDone()) );
43 timer->start( 2000, TRUE ); // 2 seconds single-shot timer
44
45 You can also use the static singleShot() function to create a single
46 shot timer.
47
48 As a special case, a QTimer with timeout 0 times out as soon as all the
49 events in the window system's event queue have been processed.
50
51 This can be used to do heavy work while providing a snappy user
52 interface:
53
54 QTimer *t = new QTimer( myObject );
55 connect( t, SIGNAL(timeout()), SLOT(processOneThing()) );
56 t->start( 0, FALSE );
57
58 myObject->processOneThing() will be called repeatedly and should return
59 quickly (typically after processing one data item) so that Qt can
60 deliver events to widgets and stop the timer as soon as it has done all
61 its work. This is the traditional way of implementing heavy work in GUI
62 applications; multi-threading is now becoming available on more and
63 more platforms, and we expect that null events will eventually be
64 replaced by threading.
65
66 Note that QTimer's accuracy depends on the underlying operating system
67 and hardware. Most platforms support an accuracy of 20ms; some provide
68 more. If Qt is unable to deliver the requested number of timer clicks,
69 it will silently discard some.
70
71 An alternative to using QTimer is to call QObject::startTimer() for
72 your object and reimplement the QObject::timerEvent() event handler in
73 your class (which must, of course, inherit QObject). The disadvantage
74 is that timerEvent() does not support such high-level features as
75 single-shot timers or signals.
76
77 Some operating systems limit the number of timers that may be used; Qt
78 tries to work around these limitations.
79
80 See also Event Classes and Time and Date.
81
84 Constructs a timer called name, with the parent parent.
85
86 Note that the parent object's destructor will destroy this timer
87 object.
88
90 Destroys the timer.
91
93 Changes the timeout interval to msec milliseconds.
94
95 If the timer signal is pending, it will be stopped and restarted;
96 otherwise it will be started.
97
98 See also start() and isActive().
99
101 Returns TRUE if the timer is running (pending); otherwise returns
102 FALSE.
103
104 Example: t11/cannon.cpp.
105
107 [static]
108 This static function calls a slot after a given time interval.
109
110 It is very convenient to use this function because you do not need to
111 bother with a timerEvent or to create a local QTimer object.
112
113 Example:
114
115 #include <qapplication.h>
116 #include <qtimer.h>
117 int main( int argc, char **argv )
118 {
119 QApplication a( argc, argv );
120 QTimer::singleShot( 10*60*1000, &a, SLOT(quit()) );
121 ... // create and show your widgets
122 return a.exec();
123 }
124
125 This sample program automatically terminates after 10 minutes (i.e.
126 600000 milliseconds).
127
128 The receiver is the receiving object and the member is the slot. The
129 time interval is msec.
130
132 Starts the timer with a msec milliseconds timeout, and returns the ID
133 of the timer, or zero when starting the timer failed.
134
135 If sshot is TRUE, the timer will be activated only once; otherwise it
136 will continue until it is stopped.
137
138 Any pending timer will be stopped.
139
140 See also singleShot(), stop(), changeInterval(), and isActive().
141
142 Examples:
143
145 Stops the timer.
146
147 See also start().
148
149 Examples:
150
152 This signal is emitted when the timer is activated.
153
154 Examples:
155
157 Returns the ID of the timer if the timer is running; otherwise returns
158 -1.
159
160
162 http://doc.trolltech.com/qtimer.html
163 http://www.trolltech.com/faq/tech.html
164
166 Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the
167 license file included in the distribution for a complete license
168 statement.
169
171 Generated automatically from the source code.
172
174 If you find a bug in Qt, please report it as described in
175 http://doc.trolltech.com/bughowto.html. Good bug reports help us to
176 help you. Thank you.
177
178 The definitive Qt documentation is provided in HTML format; it is
179 located at $QTDIR/doc/html and can be read using Qt Assistant or with a
180 web browser. This man page is provided as a convenience for those users
181 who prefer man pages, although this format is not officially supported
182 by Trolltech.
183
184 If you find errors in this manual page, please report them to qt-
185 bugs@trolltech.com. Please include the name of the manual page
186 (qtimer.3qt) and the Qt version (3.3.8).
187
188
189
190Trolltech AS 2 February 2007 QTimer(3qt)