void ValgrindRunner::traceActivity(Activity activity, const QString &buildDirCallgrind, const QString &buildDirMassif) { QString activityString; QString qbsCommand; bool dryRun; switch (activity) { case ActivityResolving: activityString = "resolving"; qbsCommand = "resolve"; dryRun = false; break; case ActivityRuleExecution: activityString = "rule-execution"; qbsCommand = "build"; dryRun = true; break; case ActivityNullBuild: activityString = "null-build"; qbsCommand = "build"; dryRun = false; break; } const QString outFileCallgrind = m_baseOutputDir + "/outfile." + activityString + ".callgrind"; const QString outFileMassif = m_baseOutputDir + "/outfile." + activityString + ".massif"; QFuture<qint64> callGrindFuture = QtConcurrent::run(this, &ValgrindRunner::runCallgrind, qbsCommand, buildDirCallgrind, dryRun, outFileCallgrind); QFuture<qint64> massifFuture = QtConcurrent::run(this, &ValgrindRunner::runMassif, qbsCommand, buildDirMassif, dryRun, outFileMassif); callGrindFuture.waitForFinished(); massifFuture.waitForFinished(); addToResults(ValgrindResult(activity, callGrindFuture.result(), massifFuture.result())); }
void QVX_Sim::IntegrateMT(IntegrationType Integrator) { switch (Integrator){ case I_EULER: { QFuture<void> res = QtConcurrent::map(BondArray.begin(), BondArray.end(), QVX_Sim::BondCalcForce); res.waitForFinished(); ////Update Forces... //int iT = NumBond(); //for (int i=0; i<iT; i++){ // QFuture<void> future = QtConcurrent::run(BondCalcForce, &BondArray[i]); // //BondArray[i].CalcForce(); //} OptimalDt = CalcMaxDt(); dt = DtFrac*OptimalDt; res = QtConcurrent::map(VoxArray.begin(), VoxArray.end(), QVX_Sim::VoxEulerStep); res.waitForFinished(); //Update positions... need to do thises seperately if we're going to do damping in the summing forces stage. // int iT = NumVox(); // for (int i=0; i<iT; i++) VoxArray[i].EulerStep(); } break; } }
void PlayListImageThumbnailHistogramGrouper::group(ImageList::iterator begin, ImageList::iterator end) { std::vector<QSharedPointer<ImageHistogram> > hists; // Load thumbnail and compute thumbnail histograms QFuture<QSharedPointer<ImageHistogram> > f = QtConcurrent::mapped(begin, end, computeImageHistogram); f.waitForFinished(); for (QSharedPointer<ImageHistogram> hist : f) { hists.push_back(hist); } // Partition std::vector<int> labels; int groupCount = cv::partition(hists, labels, isHistSame); m_groupNames.clear(); for (int i = 0; i < groupCount; i++) { m_groupNames << QStringLiteral("Group %1").arg(i); } for (auto it = begin; it != end; it++) { m_imageGroups[it->data()] = labels[it - begin]; } // Sort by group std::sort(begin, end, [this](const ImagePtr &left, const ImagePtr &right) -> bool { int leftLabel = this->m_imageGroups[left.data()]; int rightLabel = this->m_imageGroups[right.data()]; if (leftLabel != rightLabel) { return leftLabel < rightLabel; } else { return ImageNameLessThan(left->name(), right->name()); } }); }
//Destructor function, executed when closing the form. MainWindow::~MainWindow() { //Tell the PollUSBConnection() to halt gracefully threadAbortFlag = true; connectionPoller.waitForFinished(); //Wait until the thread has shut itself down delete ui; }
void auto_expand_image::run() { //qRegisterMetaType<QPainterPath >("QPainterPath"); //! =============== begin running_text_left+=running_text_left_add;//滚动字幕 if(running_text_left>=image_width)running_text_left=-running_text.textWidth(); percent_finish=1.0*(image_running_step%image_running_step_total)/(image_running_step_total-1); if(image_running_step%image_running_step_total==0){ image_switch_step++; //获取上一个图片的path if(draw_pixmap_paths.count() > 0) draw_pixmap_path_pre=draw_pixmap_paths[(image_switch_step-1)%draw_pixmap_paths.count()]; } //当前绘制的pixmap draw_pixmap_path_cur=draw_pixmap_paths[image_switch_step%draw_pixmap_paths.count()]; image_running_step++;//图片切换 //! =============== end QFuture<void> future = QtConcurrent::run(POP_INTERVAL_IMAGE, this, paint_rotate, percent_finish, polygon_vect, draw_pixmap_path_cur ); future.waitForFinished(); }
QNetworkReply::NetworkError NetworkServiceAccessor::get(const QNetworkRequest &request, QByteArray &replyData, QList<QNetworkReply::RawHeaderPair> &headers) const { QNetworkReply::NetworkError result = QNetworkReply::NoError; QFuture<void> future = QtConcurrent::run(QThreadPool::globalInstance(), [&](){ QEventLoop loop; QNetworkAccessManager networkAccessManager; QNetworkReply *reply = networkAccessManager.get(request); connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); LoggingManager::getSingleton().log() << "NetworkService Get: " << request.url().toString(); qDebug() << "NetworkService Get:" << request.url().toString(); loop.exec(); result = reply->error(); if (result != QNetworkReply::NoError) { qDebug() << "Network Service Accessor Error: " << reply->errorString(); qDebug() << "error code:" << reply->error(); LoggingManager::getSingleton().log() << "NetworkService: " << reply->errorString(); } headers = reply->rawHeaderPairs(); replyData = reply->readAll(); qDebug() << replyData; reply->deleteLater();}); future.waitForFinished(); return result; }
QNetworkReply::NetworkError NetworkServiceAccessor::post(const QNetworkRequest &request, const QByteArray &data, QByteArray &replyData) const { QNetworkReply::NetworkError result = QNetworkReply::NoError; QFuture<void> future = QtConcurrent::run(QThreadPool::globalInstance(), [&](){ QEventLoop loop; QNetworkAccessManager networkAccessManager; QNetworkReply *reply = networkAccessManager.post(request, data); connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); LoggingManager::getSingleton().log() << "NetworkService Post: " << request.url().toString(); qDebug() << "NetworkService Post: " << request.url().toString(); LoggingManager::getSingleton().log() << "Payload: " << QString::fromUtf8(data); qDebug() << "Payload: " << QString::fromUtf8(data); loop.exec(); result = reply->error(); if (result != QNetworkReply::NoError) { qDebug() << "Network Service Accessor Error: " << reply->errorString(); LoggingManager::getSingleton().log() << "NetworkService: " << reply->errorString(); } replyData = reply->readAll(); qDebug() << replyData; reply->deleteLater(); }); future.waitForFinished(); return result; }
void tst_QtConcurrentThreadEngine::cancel() { { CancelUser *engine = new CancelUser(); QFuture<void> f = engine->startAsynchronously(); f.cancel(); f.waitForFinished(); } { CancelUser *engine = new CancelUser(); QFuture<void> f = engine->startAsynchronously(); QTest::qSleep(10); f.cancel(); f.waitForFinished(); } }
void TestRunFunction::runHeavyFunction() { qDebug("starting function"); QFuture<void> future = run(F(heavy)); qDebug("waiting"); future.waitForFinished(); qDebug("done"); }
void tst_QtConcurrentRun::runLightFunction() { qDebug("starting function"); QFuture<void> future = run(F(light)); qDebug("waiting"); future.waitForFinished(); qDebug("done"); }
int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); QFuture<void> future = QtConcurrent::run(hello); qDebug() << "hello from GUI thread " << QThread::currentThread(); future.waitForFinished(); return 0; }
void tst_QtConcurrentRun::runHeavyFunction() { QThreadPool pool; qDebug("starting function"); QFuture<void> future = run(&pool, heavy); qDebug("waiting"); future.waitForFinished(); qDebug("done"); }
void tst_QtConcurrentIterateKernel::multipleResults() { QFuture<int> f = startThreadEngine(new MultipleResultsFor(0, 10)).startAsynchronously(); QCOMPARE(f.results().count() , 10); QCOMPARE(f.resultAt(0), 0); QCOMPARE(f.resultAt(5), 5); QCOMPARE(f.resultAt(9), 9); f.waitForFinished(); }
void tst_QtConcurrentThreadEngine::multipleResults() { MultipleResultsUser *engine = new MultipleResultsUser(); QFuture<int> f = engine->startAsynchronously(); QCOMPARE(f.results().count() , 10); QCOMPARE(f.resultAt(0), 0); QCOMPARE(f.resultAt(5), 5); QCOMPARE(f.resultAt(9), 9); f.waitForFinished(); }
QList<LocatorFilterEntry> BasicLocatorFilterTest::matchesFor(const QString &searchText) { doBeforeLocatorRun(); const QList<ILocatorFilter *> filters = QList<ILocatorFilter *>() << m_filter; QFuture<LocatorFilterEntry> locatorSearch = QtConcurrent::run(Core::Internal::runSearch, filters, searchText); locatorSearch.waitForFinished(); doAfterLocatorRun(); return locatorSearch.results(); }
void tst_iteratekernel::cancel() { { QFuture<void> f = startThreadEngine(new SleepPrintFor(0, 40)).startAsynchronously(); f.cancel(); f.waitForFinished(); QVERIFY(f.isCanceled()); QVERIFY(int(iterations) <= QThread::idealThreadCount()); // the threads might run one iteration each before they are canceled. } }
bool CatalogConnector::loadDataThreaded(IlwisObject *obj, const IOOptions &options){ kernel()->issues()->log(QString(TR("Scanning %1")).arg(source().url(true).toString()),IssueObject::itMessage); QVector<std::pair<CatalogExplorer *, IOOptions>> explorers; for(const auto& explorer : _dataProviders){ explorers.push_back({explorer.get(), options}); } QFuture<std::vector<Resource>> res = QtConcurrent::mappedReduced(explorers,loadExplorerData, gatherData); res.waitForFinished(); mastercatalog()->addItems(res.result()); return true; }
QList<LocatorFilterEntry> BasicLocatorFilterTest::matchesFor(const QString &searchText) { doBeforeLocatorRun(); const QList<ILocatorFilter *> filters = QList<ILocatorFilter *>() << m_filter; m_filter->prepareSearch(searchText); QFuture<LocatorFilterEntry> locatorSearch = Utils::runAsync(&Internal::runSearch, filters, searchText); locatorSearch.waitForFinished(); doAfterLocatorRun(); return locatorSearch.results(); }
void RunConcurrentMapExample() { QStringList strings; strings << "foo" << "bar" << "baz"; QFuture<void> res = QtConcurrent::map(strings,UpcaseString()); res.waitForFinished(); for(QStringList::iterator i = strings.begin(); i != strings.end(); ++i) qDebug("%s",qPrintable(*i)); }
void tst_QtConcurrentIterateKernel::cancel() { { QFuture<void> f = startThreadEngine(new SleepPrintFor(0, 40)).startAsynchronously(); f.cancel(); f.waitForFinished(); QVERIFY(f.isCanceled()); // the threads might run one iteration each before they are canceled. QVERIFY2(iterations.load() <= QThread::idealThreadCount(), (QByteArray::number(iterations.load()) + ' ' + QByteArray::number(QThread::idealThreadCount()))); } }
void tst_QtConcurrentThreadEngine::runDirectly() { { PrintUser engine; engine.startSingleThreaded(); engine.startBlocking(); } { PrintUser *engine = new PrintUser(); QFuture<void> f = engine->startAsynchronously(); f.waitForFinished(); } }
bool ActivitySessionData::setCurrentActivity(const QString &activityId) { QFuture<bool> rv; QMetaObject::invokeMethod(m_activitiesProxy, "setCurrentActivity", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QFuture<bool>, rv), Q_ARG(QString, activityId)); rv.waitForFinished(); //TODO: this shows one of the weaknesses in the QFuture based APIs .... bool value = rv.results().isEmpty() ? false : rv.result(); return value; }
// Test that a user task with a thread function that always // want to be throttled still completes. The thread engine // should make keep one thread running at all times. void tst_QtConcurrentThreadEngine::throttle() { const int repeats = 10; for (int i = 0; i < repeats; ++i) { QFuture<void> f = (new ThrottleAlwaysUser())->startAsynchronously(); f.waitForFinished(); QCOMPARE(int(count), 0); } for (int i = 0; i < repeats; ++i) { ThrottleAlwaysUser t; t.startBlocking(); QCOMPARE(int(count), 0); } }
void tst_QFuture::future() { // default constructors QFuture<int> intFuture; intFuture.waitForFinished(); QFuture<QString> stringFuture; stringFuture.waitForFinished(); QFuture<void> voidFuture; voidFuture.waitForFinished(); QFuture<void> defaultVoidFuture; defaultVoidFuture.waitForFinished(); // copy constructor QFuture<int> intFuture2(intFuture); QFuture<void> voidFuture2(defaultVoidFuture); // assigmnent operator intFuture2 = QFuture<int>(); voidFuture2 = QFuture<void>(); // state QCOMPARE(intFuture2.isStarted(), true); QCOMPARE(intFuture2.isFinished(), true); }
void ScanDir::run() { clear(); actionStr = "Make list of files..."; progressTotal = -1; QDirIterator directory(dirPath, wantRecursive ? QDirIterator::Subdirectories : QDirIterator::NoIteratorFlags); for (struct HashFile file; directory.hasNext(); file.file = directory.next()) { if (file.file.isFile()) filelist << file; } actionStr = "Calculate Hash..."; progressTotal = filelist.size(); progressValue = 0; QFuture<void> future = QtConcurrent::map(filelist, Genhash(progressValue)); future.waitForFinished(); qDebug() << progressTotal; qDebug() << progressValue; //! filelist contient maintenant une liste d'object "struct HashFile" //! filelist[i].file est un FileInfo avec les infos sur le fichier //! filelist[i].hash est un QString avec le md5 actionStr = "Compare Hashes..."; progressTotal = (filelist.size() - 1) * filelist.size() / 2; progressValue = 0; for (int i = 0; i < filelist.size(); ++i) { for (int j = i + 1; j < filelist.size(); ++j) { if (filelist[i].hash == filelist[j].hash) { filelist[i].sames << filelist[j].file; filelist[j].sames << filelist[i].file; } progressValue++; } } //! si "sames" est vide le fichier est unique //! Je sais pas trop comment tu veux faire la suite, je pence qu'écrire dans des fichiers ne demande pas trop de recources... // Donc j'imagine la suite dans Widget::threadFinish() , que j'ai renommé ^^ }
QFuture<PlaylistItemPtr> PlaylistBackend::GetPlaylistItems(int playlist) { QMutexLocker l(db_->Mutex()); QElapsedTimer timer; timer.start(); QList<SqlRow> rows = GetPlaylistRows(playlist); // it's probable that we'll have a few songs associated with the // same CUE so we're caching results of parsing CUEs std::shared_ptr<NewSongFromQueryState> state_ptr(new NewSongFromQueryState()); QFuture<PlaylistItemPtr> test = QtConcurrent::mapped( rows, std::bind(&PlaylistBackend::NewPlaylistItemFromQuery, this, _1, state_ptr)); test.waitForFinished(); QTextStream out(stdout); out << "TTIMER: " << timer.elapsed() << "\n"; return test; }
int main(int argc, char *argv[]) { ros::init(argc, argv, "intel_perceptual_server", ros::init_options::NoSigintHandler); QFuture<void> future = QtConcurrent::run(spin_function); QApplication a(argc, argv); IntelPerceptualServer app; g_app = & app; app.show(); g_initialized = true; int ret = a.exec(); future.waitForFinished(); return ret; }
int main(int argc, char **argv) { QLocale::setDefault(QLocale::C); //Scene registrations SceneRegister<SceneImage> regsceneimage("image"); try { QApplication app(argc, argv); QStringList args = app.arguments(); if (args.length() != 3) throw QString("Usage: %1 <scene.csd> <out.png>").arg(args.at(0)); Render r; QElapsedTimer timer; timer.start(); Scene scene(args.at(1)); cout << "Parsing time: " << r.showTime(timer.elapsed()).toStdString() << endl; Window win; win.resize(scene.width(), scene.height()); win.show(); win.setFileName(args.at(2)); QFuture<void> retthread = QtConcurrent::run(render, &r, &win, &scene); int ret = app.exec(); r.lock(); r.quit(); r.unlock(); retthread.waitForFinished(); return ret; } catch (const QString &s) { cerr << s.toStdString() << endl; return EXIT_FAILURE; } }
QString Logic::scanImage(int x, int y, int w, int h, const QString &pathToImage) { QFile file(pathToImage); if (file.exists()) { QImage img; img.load(pathToImage); qreal h_factor = img.height() / 540.0; qreal w_factor = img.width() / 960.0; int x_new = x >= 30 ? qRound(static_cast<qreal>(x * w_factor)) - 25 : qRound(static_cast<qreal>(x * w_factor)); int y_new = y >= 30 ? qRound(static_cast<qreal>(y * h_factor)) - 25 : qRound(static_cast<qreal>(y * h_factor)); int w_new = w < 930 ? qRound(static_cast<qreal>(w * w_factor)) + 25 : qRound(static_cast<qreal>(w * w_factor)); int h_new = h < 510 ? qRound(static_cast<qreal>(h * h_factor)) + 25 : qRound(static_cast<qreal>(h * h_factor)); QRect rect(x_new, y_new, w_new, h_new); img = img.copy(rect); QString suffix = QFileInfo(pathToImage).suffix(); QString newImageName = pathToImage; QDate date = QDate::currentDate(); QTime time = QTime::currentTime(); if (pathToImage.contains("_scan_created_", Qt::CaseInsensitive)) { newImageName.truncate(newImageName.indexOf("_scan_created_")); newImageName = newImageName + QString("_scan_created_") + date.toString("dd-MM-yyyy") + "_" + time.toString("hh:mm:ss") + "." + suffix; } else { newImageName.truncate(newImageName.lastIndexOf(".")); newImageName = newImageName + QString("_scan_created_") + date.toString("dd-MM-yyyy") + "_" + time.toString("hh:mm:ss") + "." + suffix; } // run enhancement function in another thread QFuture<void> f = QtConcurrent::run(enhanceImage, img, newImageName); f.waitForFinished(); return newImageName; } return QString(); }
ThreadedProcessor::~ThreadedProcessor() { workerThread.quit(); workerThread.wait(); if (!currentRunning.isEmpty()) { qDebug() << "currentRunning is not empty"; QHashIterator<TransformRequest *, QFuture<void> > i(currentRunning); while (i.hasNext()) { i.next(); TransformRequest * request = i.key(); // there might be a race ccondition here, not sure QFuture<void> fut = i.value(); qDebug() << " waiting for " << request; request->blockSignals(true); fut.waitForFinished(); delete request; } currentRunning.clear(); } }