'\" t
.TH QTimer 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*-
.\" Copyright 1992-2007 Trolltech ASA. 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 <ntqtimer.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
.ti -1c
.BI "int \fBtimerId\fR () const"
.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 tquickly (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 called \fIname\fR, with the parent \fIparent\fR.
.PP
Note that the parent object's destructor 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); otherwise returns FALSE.
.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 <ntqapplication.h>
.br
#include <ntqtimer.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 a \fImsec\fR milliseconds timeout, and returns the ID of the timer, or zero when starting the timer failed.
.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, distributor/distributor.ui.h, 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, distributor/distributor.ui.h, forever/forever.cpp, hello/hello.cpp, and t11/cannon.cpp.
.SH "int QTimer::timerId () const"
Returns the ID of the timer if the timer is running; otherwise returns
-1.
.SH "SEE ALSO"
.BR http://doc.trolltech.com/ntqtimer.html
.BR http://www.trolltech.com/faq/tech.html
.SH COPYRIGHT
Copyright 1992-2007 Trolltech ASA, 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.3.8).