summaryrefslogtreecommitdiffstats
path: root/doc/man/man3/tqprogressdialog.3qt
blob: 4cd2ebc6d7c99f8b15b1a10fd34d16ba6d6c2b3e (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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
'\" t
.TH QProgressDialog 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
QProgressDialog \- Feedback on the progress of a slow operation
.SH SYNOPSIS
\fC#include <ntqprogressdialog.h>\fR
.PP
Inherits QDialog.
.PP
.SS "Public Members"
.in +1c
.ti -1c
.BI "\fBQProgressDialog\fR ( QWidget * creator = 0, const char * name = 0, bool modal = FALSE, WFlags f = 0 )"
.br
.ti -1c
.BI "\fBQProgressDialog\fR ( const QString & labelText, const QString & cancelButtonText, int totalSteps, QWidget * creator = 0, const char * name = 0, bool modal = FALSE, WFlags f = 0 )"
.br
.ti -1c
.BI "\fB~QProgressDialog\fR ()"
.br
.ti -1c
.BI "void \fBsetLabel\fR ( QLabel * label )"
.br
.ti -1c
.BI "void \fBsetCancelButton\fR ( QPushButton * cancelButton )"
.br
.ti -1c
.BI "void \fBsetBar\fR ( QProgressBar * bar )"
.br
.ti -1c
.BI "bool wasCancelled () const  \fI(obsolete)\fR"
.br
.ti -1c
.BI "bool \fBwasCanceled\fR () const"
.br
.ti -1c
.BI "int \fBtotalSteps\fR () const"
.br
.ti -1c
.BI "int \fBprogress\fR () const"
.br
.ti -1c
.BI "virtual QSize \fBsizeHint\fR () const"
.br
.ti -1c
.BI "QString \fBlabelText\fR () const"
.br
.ti -1c
.BI "void \fBsetAutoReset\fR ( bool b )"
.br
.ti -1c
.BI "bool \fBautoReset\fR () const"
.br
.ti -1c
.BI "void \fBsetAutoClose\fR ( bool b )"
.br
.ti -1c
.BI "bool \fBautoClose\fR () const"
.br
.ti -1c
.BI "int \fBminimumDuration\fR () const"
.br
.in -1c
.SS "Public Slots"
.in +1c
.ti -1c
.BI "void \fBcancel\fR ()"
.br
.ti -1c
.BI "void \fBreset\fR ()"
.br
.ti -1c
.BI "void \fBsetTotalSteps\fR ( int totalSteps )"
.br
.ti -1c
.BI "void \fBsetProgress\fR ( int progress )"
.br
.ti -1c
.BI "void \fBsetProgress\fR ( int progress, int totalSteps )"
.br
.ti -1c
.BI "void \fBsetLabelText\fR ( const QString & )"
.br
.ti -1c
.BI "void \fBsetCancelButtonText\fR ( const QString & cancelButtonText )"
.br
.ti -1c
.BI "void \fBsetMinimumDuration\fR ( int ms )"
.br
.in -1c
.SS "Signals"
.in +1c
.ti -1c
.BI "void cancelled ()  \fI(obsolete)\fR"
.br
.ti -1c
.BI "void \fBcanceled\fR ()"
.br
.in -1c
.SS "Properties"
.in +1c
.ti -1c
.BI "bool \fBautoClose\fR - whether the dialog gets hidden by reset()"
.br
.ti -1c
.BI "bool \fBautoReset\fR - whether the progress dialog calls reset() as soon as progress() equals totalSteps()"
.br
.ti -1c
.BI "QString \fBlabelText\fR - the label's text"
.br
.ti -1c
.BI "int \fBminimumDuration\fR - the time that must pass before the dialog appears"
.br
.ti -1c
.BI "int \fBprogress\fR - the current amount of progress made"
.br
.ti -1c
.BI "int \fBtotalSteps\fR - the total number of steps"
.br
.ti -1c
.BI "bool \fBwasCanceled\fR - whether the dialog was canceled  \fI(read " "only" ")\fR"
.br
.ti -1c
.BI "bool wasCancelled - whether the dialog was canceled  \fI(read " "only" ")\fR  \fI(obsolete)\fR"
.br
.in -1c
.SS "Protected Slots"
.in +1c
.ti -1c
.BI "void \fBforceShow\fR ()"
.br
.in -1c
.SH DESCRIPTION
The QProgressDialog class provides feedback on the progress of a slow operation.
.PP
A progress dialog is used to give the user an indication of how long an operation is going to take, and to demonstrate that the application has not frozen. It can also give the user an opportunity to abort the operation.
.PP
A common problem with progress dialogs is that it is difficult to know when to use them; operations take different amounts of time on different hardware. QProgressDialog offers a solution to this problem: it estimates the time the operation will take (based on time for steps), and only shows itself if that estimate is beyond minimumDuration() (4 seconds by default).
.PP
Use setTotalSteps() (or the constructor) to set the number of" steps" in the operation and call setProgress() as the operation progresses. The step value can be chosen arbitrarily. It can be the number of files copied, the number of bytes received, the number of iterations through the main loop of your algorithm, or some other suitable unit. Progress starts at 0, and the progress dialog shows that the operation has finished when you call setProgress() with totalSteps() as its argument.
.PP
The dialog automatically resets and hides itself at the end of the operation. Use setAutoReset() and setAutoClose() to change this behavior.
.PP
There are two ways of using QProgressDialog: modal and modeless.
.PP
Using a modal QProgressDialog is simpler for the programmer, but you must call QApplication::processEvents() or QEventLoop::processEvents(ExcludeUserInput) to keep the event loop running to ensure that the application doesn't freeze. Do the operation in a loop, call setProgress() at intervals, and check for cancellation with wasCanceled(). For example:
.PP
.nf
.br
QProgressDialog progress( "Copying files...", "Abort Copy", numFiles,
.br
                          this, "progress", TRUE );
.br
for ( int i = 0; i < numFiles; i++ ) {
.br
    progress.setProgress( i );
.br
    tqApp->processEvents();
.br
.br
    if ( progress.wasCanceled() )
.br
        break;
.br
    //... copy one file
.br
}
.br
progress.setProgress( numFiles );
.fi
.PP
A modeless progress dialog is suitable for operations that take place in the background, where the user is able to interact with the application. Such operations are typically based on QTimer (or QObject::timerEvent()), QSocketNotifier, or QUrlOperator; or performed in a separate thread. A QProgressBar in the status bar of your main window is often an alternative to a modeless progress dialog.
.PP
You need to have an event loop to be running, connect the canceled() signal to a slot that stops the operation, and call setProgress() at intervals. For example:
.PP
.nf
.br
Operation::Operation( QObject *parent = 0 )
.br
    : QObject( parent ), steps( 0 )
.br
{
.br
    pd = new QProgressDialog( "Operation in progress.", "Cancel", 100 );
.br
    connect( pd, SIGNAL(canceled()), this, SLOT(cancel()) );
.br
    t = new QTimer( this );
.br
    connect( t, SIGNAL(timeout()), this, SLOT(perform()) );
.br
    t->start( 0 );
.br
}
.br
.br
void Operation::perform()
.br
{
.br
    pd->setProgress( steps );
.br
    //... perform one percent of the operation
.br
    steps++;
.br
    if ( steps > pd->totalSteps() )
.br
        t->stop();
.br
}
.br
.br
void Operation::cancel()
.br
{
.br
    t->stop();
.br
    //... cleanup
.br
}
.fi
.PP
In both modes the progress dialog may be customized by replacing the child widgets with custom widgets by using setLabel(), setBar(), and setCancelButton(). The functions setLabelText() and setCancelButtonText() set the texts shown.
.PP
.ce 1
.B "[Image Omitted]"
.PP

.ce 1
.B "[Image Omitted]"
.PP
See also QDialog, QProgressBar, GUI Design Handbook: Progress Indicator, and Dialog Classes.
.SH MEMBER FUNCTION DOCUMENTATION
.SH "QProgressDialog::QProgressDialog ( QWidget * creator = 0, const char * name = 0, bool modal = FALSE, WFlags f = 0 )"
Constructs a progress dialog.
.PP
Default settings:
.TP
The label text is empty.
.TP
The cancel button text is (translated) "Cancel".
.TP
The total number of steps is 100.
.PP
The \fIcreator\fR argument is the widget to use as the dialog's parent. The \fIname\fR, \fImodal\fR, and the widget flags, \fIf\fR, are passed to the QDialog::QDialog() constructor. If \fImodal\fR is FALSE (the default), you must have an event loop proceeding for any redrawing of the dialog to occur. If \fImodal\fR is TRUE, the dialog ensures that events are processed when needed.
.PP
See also labelText, setLabel(), setCancelButtonText(), setCancelButton(), and totalSteps.
.SH "QProgressDialog::QProgressDialog ( const QString & labelText, const QString & cancelButtonText, int totalSteps, QWidget * creator = 0, const char * name = 0, bool modal = FALSE, WFlags f = 0 )"
Constructs a progress dialog.
.PP
The \fIlabelText\fR is text used to remind the user what is progressing.
.PP
The \fIcancelButtonText\fR is the text to display on the cancel button, or 0 if no cancel button is to be shown.
.PP
The \fItotalSteps\fR is the total number of steps in the operation for which this progress dialog shows progress. For example, if the operation is to examine 50 files, this value would be 50. Before examining the first file, call setProgress(0). As each file is processed call setProgress(1), setProgress(2), etc., finally calling setProgress(50) after examining the last file.
.PP
The \fIcreator\fR argument is the widget to use as the dialog's parent. The \fIname\fR, \fImodal\fR, and widget flags, \fIf\fR, are passed to the QDialog::QDialog() constructor. If \fImodal\fR is FALSE (the default), you will must have an event loop proceeding for any redrawing of the dialog to occur. If \fImodal\fR is TRUE, the dialog ensures that events are processed when needed.
.PP
See also labelText, setLabel(), setCancelButtonText(), setCancelButton(), and totalSteps.
.SH "QProgressDialog::~QProgressDialog ()"
Destroys the progress dialog.
.SH "bool QProgressDialog::autoClose () const"
Returns TRUE if the dialog gets hidden by reset(); otherwise returns FALSE. See the "autoClose" property for details.
.SH "bool QProgressDialog::autoReset () const"
Returns TRUE if the progress dialog calls reset() as soon as progress() equals totalSteps(); otherwise returns FALSE. See the "autoReset" property for details.
.SH "void QProgressDialog::cancel ()\fC [slot]\fR"
Resets the progress dialog. wasCanceled() becomes TRUE until the progress dialog is reset. The progress dialog becomes hidden.
.SH "void QProgressDialog::canceled ()\fC [signal]\fR"
This signal is emitted when the cancel button is clicked. It is connected to the cancel() slot by default.
.PP
See also wasCanceled.
.SH "void QProgressDialog::cancelled ()\fC [signal]\fR"
\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code.
.PP
Use canceled() instead.
.PP
Examples:
.)l network/ftpclient/ftpmainwindow.ui.h and progress/progress.cpp.
.SH "void QProgressDialog::forceShow ()\fC [protected slot]\fR"
Shows the dialog if it is still hidden after the algorithm has been started and minimumDuration milliseconds have passed.
.PP
See also minimumDuration.
.SH "QString QProgressDialog::labelText () const"
Returns the label's text. See the "labelText" property for details.
.SH "int QProgressDialog::minimumDuration () const"
Returns the time that must pass before the dialog appears. See the "minimumDuration" property for details.
.SH "int QProgressDialog::progress () const"
Returns the current amount of progress made. See the "progress" property for details.
.SH "void QProgressDialog::reset ()\fC [slot]\fR"
Resets the progress dialog. The progress dialog becomes hidden if autoClose() is TRUE.
.PP
See also autoClose and autoReset.
.PP
Example: network/ftpclient/ftpmainwindow.ui.h.
.SH "void QProgressDialog::setAutoClose ( bool b )"
Sets whether the dialog gets hidden by reset() to \fIb\fR. See the "autoClose" property for details.
.SH "void QProgressDialog::setAutoReset ( bool b )"
Sets whether the progress dialog calls reset() as soon as progress() equals totalSteps() to \fIb\fR. See the "autoReset" property for details.
.SH "void QProgressDialog::setBar ( QProgressBar * bar )"
Sets the progress bar widget to \fIbar\fR. The progress dialog resizes to fit. The progress dialog takes ownership of the progress \fIbar\fR which will be deleted when necessary, so do not use a progress bar allocated on the stack.
.SH "void QProgressDialog::setCancelButton ( QPushButton * cancelButton )"
Sets the cancel button to the push button, \fIcancelButton\fR. The progress dialog takes ownership of this button which will be deleted when necessary, so do not pass the address of an object that is on the stack, i.e. use new() to create the button.
.PP
See also setCancelButtonText().
.SH "void QProgressDialog::setCancelButtonText ( const QString & cancelButtonText )\fC [slot]\fR"
Sets the cancel button's text to \fIcancelButtonText\fR.
.PP
See also setCancelButton().
.SH "void QProgressDialog::setLabel ( QLabel * label )"
Sets the label to \fIlabel\fR. The progress dialog resizes to fit. The label becomes owned by the progress dialog and will be deleted when necessary, so do not pass the address of an object on the stack.
.PP
See also labelText.
.PP
Example: progress/progress.cpp.
.SH "void QProgressDialog::setLabelText ( const QString & )\fC [slot]\fR"
Sets the label's text. See the "labelText" property for details.
.SH "void QProgressDialog::setMinimumDuration ( int ms )\fC [slot]\fR"
Sets the time that must pass before the dialog appears to \fIms\fR. See the "minimumDuration" property for details.
.SH "void QProgressDialog::setProgress ( int progress )\fC [slot]\fR"
Sets the current amount of progress made to \fIprogress\fR. See the "progress" property for details.
.SH "void QProgressDialog::setProgress ( int progress, int totalSteps )\fC [slot]\fR"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Sets the current amount of progress to \fIprogress\fR and the total number of steps to \fItotalSteps\fR.
.PP
See also totalSteps.
.SH "void QProgressDialog::setTotalSteps ( int totalSteps )\fC [slot]\fR"
Sets the total number of steps to \fItotalSteps\fR. See the "totalSteps" property for details.
.SH "QSize QProgressDialog::sizeHint () const\fC [virtual]\fR"
Returns a size that fits the contents of the progress dialog. The progress dialog resizes itself as required, so you should not need to call this yourself.
.SH "int QProgressDialog::totalSteps () const"
Returns the total number of steps. See the "totalSteps" property for details.
.SH "bool QProgressDialog::wasCanceled () const"
Returns TRUE if the dialog was canceled; otherwise returns FALSE. See the "wasCanceled" property for details.
.SH "bool QProgressDialog::wasCancelled () const"
Returns TRUE if the dialog was canceled; otherwise returns FALSE. See the "wasCancelled" property for details.
.SS "Property Documentation"
.SH "bool autoClose"
This property holds whether the dialog gets hidden by reset().
.PP
The default is TRUE.
.PP
See also autoReset.
.PP
Set this property's value with setAutoClose() and get this property's value with autoClose().
.SH "bool autoReset"
This property holds whether the progress dialog calls reset() as soon as progress() equals totalSteps().
.PP
The default is TRUE.
.PP
See also autoClose.
.PP
Set this property's value with setAutoReset() and get this property's value with autoReset().
.SH "QString labelText"
This property holds the label's text.
.PP
The default text is QString::null.
.PP
Set this property's value with setLabelText() and get this property's value with labelText().
.SH "int minimumDuration"
This property holds the time that must pass before the dialog appears.
.PP
If the expected duration of the task is less than the minimumDuration, the dialog will not appear at all. This prevents the dialog popping up for tasks that are quickly over. For tasks that are expected to exceed the minimumDuration, the dialog will pop up after the minimumDuration time or as soon as any progress is set.
.PP
If set to 0, the dialog is always shown as soon as any progress is set. The default is 4000 milliseconds.
.PP
Set this property's value with setMinimumDuration() and get this property's value with minimumDuration().
.SH "int progress"
This property holds the current amount of progress made.
.PP
For the progress dialog to work as expected, you should initially set this property to 0 and finally set it to QProgressDialog::totalSteps(); you can call setProgress() any number of times in-between.
.PP
\fBWarning:\fR If the progress dialog is modal (see QProgressDialog::QProgressDialog()), this function calls QApplication::processEvents(), so take care that this does not cause undesirable re-entrancy in your code. For example, don't use a QProgressDialog inside a paintEvent()!
.PP
See also totalSteps.
.PP
Set this property's value with setProgress() and get this property's value with progress().
.SH "int totalSteps"
This property holds the total number of steps.
.PP
The default is 0.
.PP
Set this property's value with setTotalSteps() and get this property's value with totalSteps().
.SH "bool wasCanceled"
This property holds whether the dialog was canceled.
.PP
Get this property's value with wasCanceled().
.PP
See also progress.
.SH "bool wasCancelled"
This property holds whether the dialog was canceled.
.PP
\fBThis property is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code.
.PP
Use wasCanceled instead.
.PP
Get this property's value with wasCancelled().

.SH "SEE ALSO"
.BR http://doc.trolltech.com/ntqprogressdialog.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 $QTDIR/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 (tqprogressdialog.3qt) and the Qt
version (3.3.8).