Archived:Create progress dialog using QProgressDialog
Article Metadata
Tested with
Compatibility
Article
Contents |
Overview
The QProgressDialog class provides feedback on the progress of a slow operation. 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. Although QProgressDialog is similar to QProgressBar, it give the user an opportunity to abort the operation, while QProgressBar will just show progress. Here you can check How to use QProgressBar.
This snippet can be self-signed. As it not use any API which require signing.
Preconditions
- Download Qt for S60 Garden release from here: Qt for S60 "Garden" pre-release
- Install Qt for S60:Installing Qt on S60
- Check this link for installation guide: How to install the package.
- Go through this article: Getting started with Qt for S60
Source code
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
ProgressDialog w;
w.showMaximized();
QVBoxLayout* layout = new QVBoxLayout;
QWidget* win = new QWidget;
//The minimum and maximum is the number of steps in the operation for which this progress dialog shows progress.
//for example here 0 and 100.
QProgressDialog* progress = new QProgressDialog("Fetching data...", "Cancel", 0, 100);
//Set dialog as modal dialog, if you want.
progress->setWindowModality(Qt::WindowModal);
layout->addWidget(progress,Qt::AlignCenter);
win->setLayout(layout);
for (int i = 0; i < 100; i++)
{
//set progress value.
progress->setValue(i);
win->show();
//if user click cancel button of dialog.
if (progress->wasCanceled())
break;
}
progress->setValue(100);
win->show();
return a.exec();
}
Other useful methods of QProgressDialog
Slots cancel () is resets the progress dialog. Signal canceled () is emitted when the cancel button is clicked. It is connected to the cancel() slot by default.
Postconditions
The code snippet is expected to show a progress dialog with cancel button, as shown in below image.
Code Example
- Download the working Code Example.

