summaryrefslogtreecommitdiffstats
path: root/doc/man/man3/tqtimer.3qt
blob: 0750c2d761a2b846fd6fedc183c5c42ad3dc0ed1 (plain)
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
191
192
193
194
195
196
'\" t
.TH TQTimer 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
TQTimer \- Timer signals and single-shot timers
.SH SYNOPSIS
\fC#include <tqtimer.h>\fR
.PP
Inherits TQObject.
.PP
.SS "Public Members"
.in +1c
.ti -1c
.BI "\fBTQTimer\fR ( TQObject * parent = 0, const char * name = 0 )"
.br
.ti -1c
.BI "\fB~TQTimer\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, TQObject * receiver, const char * member )"
.br
.in -1c
.SH DESCRIPTION
The TQTimer class provides timer signals and single-shot timers.
.PP
It uses timer events internally to provide a more versatile timer. TQTimer is very easy to use: create a TQTimer, 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 TQTimer object is destroyed automatically when its parent object is destroyed.
.PP
Example:
.PP
.nf
.br
        TQTimer *timer = new TQTimer( myObject );
.br
        connect( timer, TQ_SIGNAL(timeout()), myObject, TQ_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 TQTimer 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
        TQTimer *t = new TQTimer( myObject );
.br
        connect( t, TQ_SIGNAL(timeout()), TQ_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 TQt 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 TQTimer's accuracy depends on the underlying operating system and hardware. Most platforms support an accuracy of 20ms; some provide more. If TQt is unable to deliver the requested number of timer clicks, it will silently discard some.
.PP
An alternative to using TQTimer is to call TQObject::startTimer() for your object and reimplement the TQObject::timerEvent() event handler in your class (which must, of course, inherit TQObject). 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; TQt tries to work around these limitations.
.PP
See also Event Classes and Time and Date.
.SH MEMBER FUNCTION DOCUMENTATION
.SH "TQTimer::TQTimer ( TQObject * 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 "TQTimer::~TQTimer ()"
Destroys the timer.
.SH "void TQTimer::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 TQTimer::isActive () const"
Returns TRUE if the timer is running (pending); otherwise returns FALSE.
.PP
Example: t11/cannon.cpp.
.SH "void TQTimer::singleShot ( int msec, TQObject * 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 TQTimer object.
.PP
Example:
.PP
.nf
.br
        #include <ntqapplication.h>
.br
        #include <tqtimer.h>
.br
.br
        int main( int argc, char **argv )
.br
        {
.br
            QApplication a( argc, argv );
.br
            TQTimer::singleShot( 10*60*1000, &a, TQ_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 TQTimer::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 TQTimer::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 TQTimer::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 TQTimer::timerId () const"
Returns the ID of the timer if the timer is running; otherwise returns
-1.

.SH "SEE ALSO"
.BR http://doc.trolltech.com/tqtimer.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 TQt documentation is provided in HTML format; it is
located at $TQTDIR/doc/html and can be read using TQt 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 (tqtimer.3qt) and the Qt
version (3.3.8).