Namespaces
Variants
Actions
Revision as of 04:13, 11 October 2012 by hamishwillee (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Archived:Create progress dialog using QProgressDialog

Jump to: navigation, search
Archived.png
Archived: 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 Example
Tested with
Devices(s): Nokia 5800

Compatibility
Platform(s): S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition

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

445 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved