summaryrefslogtreecommitdiff
path: root/examples/qtconcurrent/progressdialog/main.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-11-21 14:34:31 +0100
committerLiang Qi <liang.qi@qt.io>2017-11-23 09:36:03 +0100
commit153e8b49adfe210cb00490284a14c94c08e03c3f (patch)
tree59d9522d6dc96215cc2cb1d19b3e8a0e580bcb41 /examples/qtconcurrent/progressdialog/main.cpp
parentef7c0594bf9e41813c9c841e00c3a52269d363f5 (diff)
parenta4113d0c644edba1c39d9d268a259e95ae51c61e (diff)
downloadqtbase-153e8b49adfe210cb00490284a14c94c08e03c3f.tar.gz
Merge remote-tracking branch 'origin/5.10' into dev
Conflicts: src/network/access/qhttp2protocolhandler_p.h src/network/kernel/kernel.pri src/network/ssl/qsslkey_qt.cpp src/plugins/platforms/cocoa/qcocoascreen.mm src/plugins/platforms/windows/accessible/iaccessible2.cpp src/plugins/platforms/windows/accessible/iaccessible2.h src/plugins/platforms/windows/accessible/qwindowsaccessibility.cpp src/plugins/platforms/windows/accessible/qwindowsmsaaaccessible.cpp src/plugins/platforms/windows/accessible/qwindowsmsaaaccessible.h src/widgets/widgets/qmenu_p.h tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp tests/auto/other/qaccessibility/tst_qaccessibility.cpp tests/auto/testlib/selftests/expected_cmptest.lightxml tests/auto/testlib/selftests/expected_cmptest.teamcity tests/auto/testlib/selftests/expected_cmptest.txt tests/auto/testlib/selftests/expected_cmptest.xml Done-with: Edward Welbourne <edward.welbourne@qt.io> Change-Id: I4217cc7d840cbae3e3dd28574741544469c4c6b9
Diffstat (limited to 'examples/qtconcurrent/progressdialog/main.cpp')
-rw-r--r--examples/qtconcurrent/progressdialog/main.cpp34
1 files changed, 18 insertions, 16 deletions
diff --git a/examples/qtconcurrent/progressdialog/main.cpp b/examples/qtconcurrent/progressdialog/main.cpp
index 0f251c00f1..c277111813 100644
--- a/examples/qtconcurrent/progressdialog/main.cpp
+++ b/examples/qtconcurrent/progressdialog/main.cpp
@@ -51,24 +51,16 @@
#include <QtWidgets>
#include <QtConcurrent>
-using namespace QtConcurrent;
-
-const int iterations = 20;
+#include <functional>
-void spin(int &iteration)
-{
- const int work = 1000 * 1000 * 40;
- volatile int v = 0;
- for (int j = 0; j < work; ++j)
- ++v;
-
- qDebug() << "iteration" << iteration << "in thread" << QThread::currentThreadId();
-}
+using namespace QtConcurrent;
int main(int argc, char **argv)
{
QApplication app(argc, argv);
+ const int iterations = 20;
+
// Prepare the vector.
QVector<int> vector;
for (int i = 0; i < iterations; ++i)
@@ -80,10 +72,20 @@ int main(int argc, char **argv)
// Create a QFutureWatcher and connect signals and slots.
QFutureWatcher<void> futureWatcher;
- QObject::connect(&futureWatcher, SIGNAL(finished()), &dialog, SLOT(reset()));
- QObject::connect(&dialog, SIGNAL(canceled()), &futureWatcher, SLOT(cancel()));
- QObject::connect(&futureWatcher, SIGNAL(progressRangeChanged(int,int)), &dialog, SLOT(setRange(int,int)));
- QObject::connect(&futureWatcher, SIGNAL(progressValueChanged(int)), &dialog, SLOT(setValue(int)));
+ QObject::connect(&futureWatcher, &QFutureWatcher<void>::finished, &dialog, &QProgressDialog::reset);
+ QObject::connect(&dialog, &QProgressDialog::canceled, &futureWatcher, &QFutureWatcher<void>::cancel);
+ QObject::connect(&futureWatcher, &QFutureWatcher<void>::progressRangeChanged, &dialog, &QProgressDialog::setRange);
+ QObject::connect(&futureWatcher, &QFutureWatcher<void>::progressValueChanged, &dialog, &QProgressDialog::setValue);
+
+ // Our function to compute
+ std::function<void(int&)> spin = [](int &iteration) {
+ const int work = 1000 * 1000 * 40;
+ volatile int v = 0;
+ for (int j = 0; j < work; ++j)
+ ++v;
+
+ qDebug() << "iteration" << iteration << "in thread" << QThread::currentThreadId();
+ };
// Start the computation.
futureWatcher.setFuture(QtConcurrent::map(vector, spin));