diff options
author | Liang Qi <liang.qi@qt.io> | 2017-11-09 11:05:03 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-11-09 11:47:57 +0100 |
commit | 88cf04458002d863750e9121af7dcd9bcbfaa169 (patch) | |
tree | caccae211eef1a27fa5caae3a8403830b615bd5e /examples/qtconcurrent/progressdialog/main.cpp | |
parent | 19b0ce5daa31e2ffebfcf2701143742302f1deb4 (diff) | |
parent | 579d0cb2bed193ccb1901b121a360f85d1c57a54 (diff) |
Merge remote-tracking branch 'origin/5.9' into 5.10
Conflicts:
src/gui/kernel/qwindow.cpp
src/plugins/platforms/cocoa/qcocoawindow.mm
src/plugins/platforms/windows/qwindowssystemtrayicon.cpp
src/plugins/platforms/xcb/qxcbconnection_xi2.cpp
tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp
tests/auto/widgets/kernel/qaction/tst_qaction.cpp
Change-Id: Ifa515dc0ece7eb1471b00c1214149629a7e6a233
Diffstat (limited to 'examples/qtconcurrent/progressdialog/main.cpp')
-rw-r--r-- | examples/qtconcurrent/progressdialog/main.cpp | 34 |
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)); |