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
|
'\" t
.TH QTimer 3qt "18 March 2002" "Trolltech AS" \" -*- nroff -*-
.\" Copyright 1992-2001 Trolltech AS. All rights reserved. See the
.\" license file included in the distribution for a complete license
.\" statement.
.\"
.ad l
.nh
.SH NAME
QTimer \- Timer signals and single-shot timers
.SH SYNOPSIS
\fC#include <qtimer.h>\fR
.PP
Inherits QObject.
.PP
.SS "Public Members"
.in +1c
.ti -1c
.BI "\fBQTimer\fR ( QObject * parent = 0, const char * name = 0 )"
.br
.ti -1c
.BI "\fB~QTimer\fR ()"
.br
.ti -1c
.BI "bool \fBisActive\fR () const"
.br
.ti -1c
.BI "int \fBstart\fR ( int msec, bool sshot = FALSE )"
.br
.ti -1c
.BI "void \fBchangeInterval\fR ( int msec )"
.br
.ti -1c
.BI "void \fBstop\fR ()"
.br
.in -1c
.SS "Signals"
.in +1c
.ti -1c
.BI "void \fBtimeout\fR ()"
.br
.in -1c
.SS "Static Public Members"
.in +1c
.ti -1c
.BI "void \fBsingleShot\fR ( int msec, QObject * receiver, const char * member )"
.br
.in -1c
.SH DESCRIPTION
The QTimer class provides timer signals and single-shot timers.
.PP
It uses timer events internally to provide a more versatile timer. QTimer is very easy to use: create a QTimer, call start() to start it and connect its timeout() to the appropriate slots. When the time is up it will emit the timeout() signal.
.PP
Note that a QTimer object is destroyed automatically when its parent object is destroyed.
.PP
Example:
.PP
.nf
.br
QTimer *timer = new QTimer( myObject );
.br
connect( timer, SIGNAL(timeout()), myObject, SLOT(timerDone()) );
.br
timer->start( 2000, TRUE ); // 2 seconds single-shot timer
.br
.fi
.PP
You can also use the static singleShot() function to create a single shot timer.
.PP
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.
.PP
This can be used to do heavy work while providing a snappy user interface:
.PP
.nf
.br
QTimer *t = new QTimer( myObject );
.br
connect( t, SIGNAL(timeout()), SLOT(processOneThing()) );
.br
t->start( 0, FALSE );
.br
.fi
.PP
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.
.PP
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.
.PP
An alternative to using QTimer is to call QObject::startTimer() for your object and reimplement the QObject::timerEvent() event handler in your class (which must, of course, inherit QObject). The disadvantage is that timerEvent() does not support such high-level features as single-shot timers or signals.
.PP
Some operating systems limit the number of timers that may be used; Qt tries to work around these limitations.
.PP
See also Event Classes and Time and Date.
.SH MEMBER FUNCTION DOCUMENTATION
.SH "QTimer::QTimer ( QObject * parent = 0, const char * name = 0 )"
Constructs a timer with a \fIparent\fR and a \fIname\fR.
.PP
Note that the destructor of the parent object will destroy this timer object.
.SH "QTimer::~QTimer ()"
Destroys the timer.
.SH "void QTimer::changeInterval ( int msec )"
Changes the timeout interval to \fImsec\fR milliseconds.
.PP
If the timer signal is pending, it will be stopped and restarted; otherwise it will be started.
.PP
See also start() and isActive().
.SH "bool QTimer::isActive () const"
Returns TRUE if the timer is running (pending) or FALSE if the timer is idle.
.PP
Example: t11/cannon.cpp.
.SH "void QTimer::singleShot ( int msec, QObject * receiver, const char * member )\fC [static]\fR"
This static function calls a slot after a given time interval.
.PP
It is very convenient to use this function because you do not need to bother with a timerEvent or to create a local QTimer object.
.PP
Example:
.PP
.nf
.br
#include <qapplication.h>
.br
#include <qtimer.h>
.br
.br
int main( int argc, char **argv )
.br
{
.br
QApplication a( argc, argv );
.br
QTimer::singleShot( 10*60*1000, &a, SLOT(quit()) );
.br
... // create and show your widgets
.br
return a.exec();
.br
}
.br
.fi
.PP
This sample program automatically terminates after 10 minutes (i.e. 600000 milliseconds).
.PP
The \fIreceiver\fR is the receiving object and the \fImember\fR is the slot. The time interval is \fImsec\fR.
.SH "int QTimer::start ( int msec, bool sshot = FALSE )"
Starts the timer with an \fImsec\fR milliseconds timeout.
.PP
If \fIsshot\fR is TRUE, the timer will be activated only once; otherwise it will continue until it is stopped.
.PP
Any pending timer will be stopped.
.PP
See also singleShot(), stop(), changeInterval() and isActive().
.PP
Examples:
.)l aclock/aclock.cpp, dirview/dirview.cpp, forever/forever.cpp, hello/hello.cpp, t11/cannon.cpp and t13/cannon.cpp.
.SH "void QTimer::stop ()"
Stops the timer.
.PP
See also start().
.PP
Examples:
.)l dirview/dirview.cpp, t11/cannon.cpp, t12/cannon.cpp and t13/cannon.cpp.
.SH "void QTimer::timeout ()\fC [signal]\fR"
This signal is emitted when the timer is activated.
.PP
Examples:
.)l aclock/aclock.cpp, dirview/dirview.cpp, forever/forever.cpp, hello/hello.cpp and t11/cannon.cpp.
.SH "SEE ALSO"
.BR http://doc.trolltech.com/qtimer.html
.BR http://www.trolltech.com/faq/tech.html
.SH COPYRIGHT
Copyright 1992-2001 Trolltech AS, http://www.trolltech.com. See the
license file included in the distribution for a complete license
statement.
.SH AUTHOR
Generated automatically from the source code.
.SH BUGS
If you find a bug in Qt, please report it as described in
.BR http://doc.trolltech.com/bughowto.html .
Good bug reports help us to help you. Thank you.
.P
The definitive Qt documentation is provided in HTML format; it is
located at $QTDIR/doc/html and can be read using Qt Assistant or with
a web browser. This man page is provided as a convenience for those
users who prefer man pages, although this format is not officially
supported by Trolltech.
.P
If you find errors in this manual page, please report them to
.BR qt-bugs@trolltech.com .
Please include the name of the manual page (qtimer.3qt) and the Qt
version (3.0.3).
|