Progress Bar

From Qt Wiki
Revision as of 16:18, 14 January 2015 by Maintenance script (talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Progress Bar

It is often necessary to display a progress bar while a long operation is happening. The case we are concerned about in this example is when there is no easy way to track the progress of the operation – all that is known is when it is done. There are many ways to do this. You could use a progressBar widget on your widget and run the operation in a different thread (using moveToThread()). This typically requires a special object to be created (a subclass of QObject [developer.qt.nokia.com] that runs the operation and then emits a finished() signal), which can be a pain if you need to do this for many different operations.

However, using QFutureWatcher [developer.qt.nokia.com] and QtConcurrent::run() [developer.qt.nokia.com], this is extremely easy. Below we demonstrate how to use this technique with both a QProgressDialog and a QProgressBar.

QProgressBar Example

form.h

form.cpp

form.ui

FutureWatcher.cpp

MyClass.h

CMakeLists.txt

QProgressDialog Example

form.h

form.cpp

form.ui

MyClass.h

FutureWatcherProgressDialog.cpp

Categories: