Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Archived:Create progress dialog using QProgressDialog

From Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Qt Quick should be used for all UI development on mobile devices. The approach described in this article (based on QWidget) is deprecated.

Article Metadata
Code ExampleTested with
Devices(s): Nokia 5800
Compatibility
Platform(s): S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition
Symbian
Platform Security
Signing Required: Self-Signed
Capabilities: None
Article
Keywords: QProgressDialog
Created: savaj (06 Jun 2009)
Last edited: hamishwillee (11 Oct 2012)

Contents

Overview

This code snippet shows how to use the QProgressDialog class to provide feedback on the progress of a slow operation. Note that the QProgressDialog is similar to QProgressBar, but additionally gives users to opportunity to abort the operation - see How to use QProgressBar in Qt.

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

Slot cancel() 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.

QtProgressDialog.PNG

Code Example

This page was last modified on 11 October 2012, at 01:13.
130 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×