void BaseFileFind::runSearch(SearchResult *search) { FileFindParameters parameters = search->userData().value<FileFindParameters>(); CountingLabel *label = new CountingLabel; connect(search, &SearchResult::countChanged, label, &CountingLabel::updateCount); CountingLabel *statusLabel = new CountingLabel; connect(search, &SearchResult::countChanged, statusLabel, &CountingLabel::updateCount); SearchResultWindow::instance()->popup(IOutputPane::Flags(IOutputPane::ModeSwitch|IOutputPane::WithFocus)); QFutureWatcher<FileSearchResultList> *watcher = new QFutureWatcher<FileSearchResultList>(); d->m_watchers.insert(watcher, search); watcher->setPendingResultsLimit(1); connect(watcher, &QFutureWatcherBase::resultReadyAt, this, &BaseFileFind::displayResult); connect(watcher, &QFutureWatcherBase::finished, this, &BaseFileFind::searchFinished); if (parameters.flags & FindRegularExpression) { watcher->setFuture(Utils::findInFilesRegExp(parameters.text, files(parameters.nameFilters, parameters.additionalParameters), textDocumentFlagsForFindFlags(parameters.flags), TextDocument::openedTextDocumentContents())); } else { watcher->setFuture(Utils::findInFiles(parameters.text, files(parameters.nameFilters, parameters.additionalParameters), textDocumentFlagsForFindFlags(parameters.flags), TextDocument::openedTextDocumentContents())); } FutureProgress *progress = ProgressManager::addTask(watcher->future(), tr("Searching"), Constants::TASK_SEARCH); progress->setWidget(label); progress->setStatusBarWidget(statusLabel); connect(progress, &FutureProgress::clicked, search, &SearchResult::popup); }
void BaseFileFind::runSearch(Find::SearchResult *search) { FileFindParameters parameters = search->userData().value<FileFindParameters>(); CountingLabel *label = new CountingLabel; connect(search, SIGNAL(countChanged(int)), label, SLOT(updateCount(int))); Find::SearchResultWindow::instance()->popup(true); QFutureWatcher<FileSearchResultList> *watcher = new QFutureWatcher<FileSearchResultList>(); m_watchers.insert(watcher, search); watcher->setPendingResultsLimit(1); connect(watcher, SIGNAL(resultReadyAt(int)), this, SLOT(displayResult(int))); connect(watcher, SIGNAL(finished()), this, SLOT(searchFinished())); if (parameters.flags & Find::FindRegularExpression) { watcher->setFuture(Utils::findInFilesRegExp(parameters.text, files(parameters.nameFilters, parameters.additionalParameters), textDocumentFlagsForFindFlags(parameters.flags), ITextEditor::openedTextEditorsContents())); } else { watcher->setFuture(Utils::findInFiles(parameters.text, files(parameters.nameFilters, parameters.additionalParameters), textDocumentFlagsForFindFlags(parameters.flags), ITextEditor::openedTextEditorsContents())); } Core::FutureProgress *progress = Core::ICore::progressManager()->addTask(watcher->future(), tr("Search"), QLatin1String(Constants::TASK_SEARCH)); progress->setWidget(label); connect(progress, SIGNAL(clicked()), search, SLOT(popup())); }
void MeshCurvature::ComputePerFace(bool parallel) { Base::Vector3f rkDir0, rkDir1, rkPnt; Base::Vector3f rkNormal; myCurvature.clear(); MeshRefPointToFacets search(myKernel); FacetCurvature face(myKernel, search, myRadius, myMinPoints); if (!parallel) { Base::SequencerLauncher seq("Curvature estimation", mySegment.size()); for (std::vector<unsigned long>::iterator it = mySegment.begin(); it != mySegment.end(); ++it) { CurvatureInfo info = face.Compute(*it); myCurvature.push_back(info); seq.next(); } } else { QFuture<CurvatureInfo> future = QtConcurrent::mapped (mySegment, boost::bind(&FacetCurvature::Compute, &face, _1)); QFutureWatcher<CurvatureInfo> watcher; watcher.setFuture(future); watcher.waitForFinished(); for (QFuture<CurvatureInfo>::const_iterator it = future.begin(); it != future.end(); ++it) { myCurvature.push_back(*it); } } }
int64_t DownloadSizeFinder::downloadOrQueue(const QString &url, QString *err) { int64_t r = -2; *err = ""; this->mutex.lock(); if (this->files.contains(url)) { QString v = this->files.value(url); if (v.startsWith('*')) *err = v.mid(1); else r = v.toLongLong(); this->mutex.unlock(); } else { this->mutex.unlock(); QFuture<DownloadFile> future = run(&threadPool, this, &DownloadSizeFinder::downloadRunnable, url); QFutureWatcher<DownloadFile>* w = new QFutureWatcher<DownloadFile>(this); connect(w, SIGNAL(finished()), this, SLOT(watcherFinished())); w->setFuture(future); } return r; }
void AttachDialog::updateProcesses() { QFutureWatcher<ProcDataList> *watcher = new QFutureWatcher<ProcDataList>(this); connect(watcher, SIGNAL(finished()), this, SLOT(updateProcessesFinished())); watcher->setFuture(QtConcurrent::run(processList, m_model->processes())); }
void CmdSandboxMeshLoaderFuture::activated(int iMsg) { // use current path as default QStringList filter; filter << QObject::tr("All Mesh Files (*.stl *.ast *.bms *.obj)"); filter << QObject::tr("Binary STL (*.stl)"); filter << QObject::tr("ASCII STL (*.ast)"); filter << QObject::tr("Binary Mesh (*.bms)"); filter << QObject::tr("Alias Mesh (*.obj)"); filter << QObject::tr("Inventor V2.1 ascii (*.iv)"); //filter << "Nastran (*.nas *.bdf)"; filter << QObject::tr("All Files (*.*)"); // Allow multi selection QStringList fn = Gui::FileDialog::getOpenFileNames(Gui::getMainWindow(), QObject::tr("Import mesh"), QString(), filter.join(QLatin1String(";;"))); QFuture< Base::Reference<Mesh::MeshObject> > future = QtConcurrent::mapped (fn, loadMesh); QFutureWatcher< Base::Reference<Mesh::MeshObject> > watcher; watcher.setFuture(future); // keep it responsive during computation QEventLoop loop; QObject::connect(&watcher, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); App::Document* doc = App::GetApplication().getActiveDocument(); for (QFuture< Base::Reference<Mesh::MeshObject> >::const_iterator it = future.begin(); it != future.end(); ++it) { Mesh::Feature* mesh = static_cast<Mesh::Feature*>(doc->addObject("Mesh::Feature","Mesh")); mesh->Mesh.setValuePtr((Mesh::MeshObject*)(*it)); mesh->purgeTouched(); } }
void DocsetRegistry::loadDocset(const QString &path) { QFutureWatcher<Docset *> *watcher = new QFutureWatcher<Docset *>(); connect(watcher, &QFutureWatcher<Docset *>::finished, this, [this, watcher] { QScopedPointer<QFutureWatcher<Docset *>, QScopedPointerDeleteLater> guard(watcher); Docset *docset = watcher->result(); // TODO: Emit error if (!docset->isValid()) { qWarning("Could not load docset from '%s'. Reinstall the docset.", qPrintable(docset->path())); delete docset; return; } docset->setFuzzySearchEnabled(m_fuzzySearchEnabled); const QString name = docset->name(); if (m_docsets.contains(name)) { unloadDocset(name); } m_docsets[name] = docset; emit docsetLoaded(name); }); watcher->setFuture(QtConcurrent::run([path] { return new Docset(path); })); }
void TrackSelectionDialog::accept() { if (save_on_close_) { SetLoading(tr("Saving tracks") + "..."); // Save tags in the background QFuture<void> future = QtConcurrent::run(&TrackSelectionDialog::SaveData, data_); QFutureWatcher<void>* watcher = new QFutureWatcher<void>(this); watcher->setFuture(future); connect(watcher, SIGNAL(finished()), SLOT(AcceptFinished())); return; } QDialog::accept(); for (const Data& data : data_) { if (data.pending_ || data.results_.isEmpty() || data.selected_result_ == -1) continue; const Song& new_metadata = data.results_[data.selected_result_]; emit SongChosen(data.original_song_, new_metadata); } }
int QgsDemHeightMapGenerator::render( int x, int y, int z ) { Q_ASSERT( mJobs.isEmpty() ); // should be always just one active job... // extend the rect by half-pixel on each side? to get the values in "corners" QgsRectangle extent = mTilingScheme.tileToExtent( x, y, z ); float mapUnitsPerPixel = extent.width() / mResolution; extent.grow( mapUnitsPerPixel / 2 ); // but make sure not to go beyond the full extent (returns invalid values) QgsRectangle fullExtent = mTilingScheme.tileToExtent( 0, 0, 0 ); extent = extent.intersect( &fullExtent ); JobData jd; jd.jobId = ++mLastJobId; jd.extent = extent; jd.timer.start(); // make a clone of the data provider so it is safe to use in worker thread jd.future = QtConcurrent::run( _readDtmData, mClonedProvider, extent, mResolution ); QFutureWatcher<QByteArray> *fw = new QFutureWatcher<QByteArray>; fw->setFuture( jd.future ); connect( fw, &QFutureWatcher<QByteArray>::finished, this, &QgsDemHeightMapGenerator::onFutureFinished ); mJobs.insert( fw, jd ); return jd.jobId; }
void PatternManager::thresholdImages() { qDebug() << "img thresholding"; if (!m_mtWatchers.isEmpty()) { qDebug("Error: the watchers queue is not empty!"); return; } //Fix me this synchronous logic and not threadsafe... mt_grayDecoder decoder2; std::vector<cv::Mat*> orgStdVec = m_originalPatterns.toStdVector(); min = *decoder2.findExtremeMinPixels(&orgStdVec); max = *decoder2.findExtremeMaxPixels(&orgStdVec); diff = *decoder2.findExtremeMinMaxDiffPixels(min, max); QVectorIterator<cv::Mat*> it(m_originalPatterns); while ( it.hasNext() ) { cv::Mat* origPtr = it.next(); QFutureWatcher<cv::Mat*>* mtWatcher = new QFutureWatcher<cv::Mat*>(); //QObject::connect(mtWatcher, SIGNAL(finished)), this, SLOT(fileLoaded(cv::Mat*)) QObject::connect(mtWatcher, SIGNAL(finished()), this, SLOT(thresholdImageFinished())); mt_grayDecoder decoder; QFuture<cv::Mat*> thresholder = QtConcurrent::run(decoder, &mt_grayDecoder::thresholdImage, origPtr, min, diff); mtWatcher->setFuture(thresholder); //m_mtWatchers.enqueue(mtWatcher); qDebug() << "img thresholding"; } }
bool PatternManager::loadFiles(QStringList fileNames) { if (!m_mtWatchers.isEmpty()) { qDebug("Error: the watchers queue is not empty!"); return false; } //clear current contents clearOriginalPatterns(); //save the size of the list of filenames patternSetSize = fileNames.size(); emit patternSetSizeSet(fileNames.size()); //iterate the filenames QStringListIterator it(fileNames); while ( it.hasNext() ) { QString fileName = it.next(); QFutureWatcher<cv::Mat*>* mtWatcher = new QFutureWatcher<cv::Mat*>(); //this doesn't work because of the while loop at the end QObject::connect(mtWatcher, SIGNAL(finished()), this, SLOT(fileLoadFinished())); //class method only works with internal member methods (not static so you need an instance) //see thresholdImage //mt_grayDecoder decoder;// = new mt_grayDecoder(); //QFuture<cv::Mat*> fileLoader = QtConcurrent::run(decoder, &mt_grayDecoder::loadFile, fileName.toStdString()); //static method only works with static methods in the class(simple) QFuture<cv::Mat*> fileLoader = QtConcurrent::run(mt_grayDecoder::loadFile, fileName.toStdString()); mtWatcher->setFuture(fileLoader); //m_mtWatchers.enqueue(mtWatcher); qDebug() << "file "<< fileName << " loading"; } return true; }
QVariant ThumbnailModel::data(const QModelIndex &index, int role) const { if (role == Qt::DecorationRole && index.isValid()) { QString id = itemId(index).toString(); QFutureWatcher<QImage> *future = cache.object(id); if (!future) { future = new QFutureWatcher<QImage>; QString path = imagePath(index); if (!path.isEmpty()) { future->setFuture(QtConcurrent::run(ThumbnailModel::load, path)); connect(future, SIGNAL(finished()), this, SLOT(thumbnailLoaded())); } cache.insert(id, future); } return !future->isCanceled() ? future->result() : QVariant(); } else { return QGalleryQueryModel::data(index, role); } }
QFuture<void> QgsGeometryChecker::execute( int *totalSteps ) { if ( totalSteps ) { *totalSteps = 0; for ( QgsGeometryCheck *check : qgis::as_const( mChecks ) ) { for ( auto it = mContext->featurePools.constBegin(); it != mContext->featurePools.constEnd(); ++it ) { if ( check->getCheckType() <= QgsGeometryCheck::FeatureCheck ) { *totalSteps += check->getCompatibility( it.value()->getLayer()->geometryType() ) ? it.value()->getFeatureIds().size() : 0; } else { *totalSteps += 1; } } } } QFuture<void> future = QtConcurrent::map( mChecks, RunCheckWrapper( this ) ); QFutureWatcher<void> *watcher = new QFutureWatcher<void>(); watcher->setFuture( future ); QTimer *timer = new QTimer(); connect( timer, &QTimer::timeout, this, &QgsGeometryChecker::emitProgressValue ); connect( watcher, &QFutureWatcherBase::finished, timer, &QObject::deleteLater ); connect( watcher, &QFutureWatcherBase::finished, watcher, &QObject::deleteLater ); timer->start( 500 ); return future; }
void executeProgressWatcher(QWidget *parent, const QString& title, Sequence& sequence, MapFunction function) { QProgressDialog progress(parent); { QString t = title; const int num = QThread::idealThreadCount(); if( num > 1 ) { t.append(QObject::tr(" (%1 Threads)").arg(num)); } progress.setWindowTitle(t); } QFutureWatcher<void> watcher; QObject::connect(&watcher, SIGNAL(finished()), &progress, SLOT(reset())); QObject::connect(&watcher, SIGNAL(progressRangeChanged(int, int)), &progress, SLOT(setRange(int, int))); QObject::connect(&watcher, SIGNAL(progressValueChanged(int)), &progress, SLOT(setValue(int))); QObject::connect(&progress, SIGNAL(canceled()), &watcher, SLOT(cancel())); watcher.setFuture(QtConcurrent::map(sequence, function)); progress.exec(); watcher.waitForFinished(); }
void tst_QFutureWatcher::progressValueChanged() { #ifdef PRINT qDebug() << "main thread" << QThread::currentThread(); #endif progressValues.clear(); const int listSize = 20; QList<int> list = createList(listSize); QFutureWatcher<void> futureWatcher; ProgressObject progressObject; QObject::connect(&futureWatcher, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); #ifdef PRINT QObject::connect(&futureWatcher, SIGNAL(progressValueChanged(int)), &progressObject, SLOT(printProgress(int)), Qt::DirectConnection ); #endif QObject::connect(&futureWatcher, SIGNAL(progressValueChanged(int)), &progressObject, SLOT(registerProgress(int))); futureWatcher.setFuture(QtConcurrent::map(list, mapSleeper)); QTestEventLoop::instance().enterLoop(5); QVERIFY(!QTestEventLoop::instance().timeout()); futureWatcher.disconnect(); QVERIFY(progressValues.contains(0)); QVERIFY(progressValues.contains(listSize)); }
sqlqueryresultlist searchhandler::perform_grep(QString searchtxt, sqlqueryresultlist searchlist, bool exactmatch) { QVector<QString> strvec; sqlqueryresultlist resultlist; QFutureWatcher<sqlqueryresultlist> futureWatcher; QProgressDialog dialog; unsigned int n = searchlist.resultlist.size(); if (n == 0) return resultlist; strvec.resize(n); for (unsigned int i=0; i < n; i++) { strvec.replace(i, str2qt(searchlist.resultlist[i].filepath)); } dialog.setAutoReset(false); dialog.setLabelText(QString("Grep ").append(QString(tr("in progress"))).append(QString(" ..."))); dialog.setCancelButtonText(tr("Cancel")); 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))); m_grepExactMatch = exactmatch; (*m_grepRegExp) = QRegExp(searchtxt.toAscii().data(), Qt::CaseInsensitive); m_grepRegExp->setPatternSyntax(QRegExp::RegExp2); futureWatcher.setFuture(QtConcurrent::mappedReduced(strvec, doGrep, collateGrep, QtConcurrent::SequentialReduce)); dialog.exec(); futureWatcher.waitForFinished(); if (futureWatcher.isCanceled() == false) resultlist = futureWatcher.result(); return resultlist; }
void downloadFile() { QTemporaryFile file; file.setAutoRemove(false); if (file.open()) { const QString filename = file.fileName(); QInstaller::blockingWrite(&file, QByteArray(scLargeSize, '1')); file.close(); DownloadFileTask fileTask(QLatin1String("file:///") + filename); QFutureWatcher<FileTaskResult> watcher; QSignalSpy started(&watcher, SIGNAL(started())); QSignalSpy finished(&watcher, SIGNAL(finished())); QSignalSpy progress(&watcher, SIGNAL(progressValueChanged(int))); watcher.setFuture(QtConcurrent::run(&DownloadFileTask::doTask, &fileTask)); watcher.waitForFinished(); QTest::qWait(10); // Spin the event loop to deliver queued signals. QCOMPARE(started.count(), 1); QCOMPARE(finished.count(), 1); FileTaskResult result = watcher.result(); QCOMPARE(watcher.future().resultCount(), 1); QVERIFY(QFile(result.target()).exists()); QCOMPARE(file.size(), QFile(result.target()).size()); QCOMPARE(result.checkSum().toHex(), QByteArray("85304f87b8d90554a63c6f6d1e9cc974fbef8d32")); } }
void test01(){ // Prepare the vector. QVector<int> vector; for (int i = 0; i < iterations; ++i) vector.append(i); // Create a progress dialog. QProgressDialog dialog; dialog.setLabelText(QString("Progressing using %1 thread(s)...").arg(QThread::idealThreadCount())); // 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))); // Start the computation. futureWatcher.setFuture(QtConcurrent::map(vector, spin)); // Display the dialog and start the event loop. dialog.exec(); futureWatcher.waitForFinished(); // Query the future to check if was canceled. qDebug() << "Canceled?" << futureWatcher.future().isCanceled(); }
http::Response * Server::wait(QFuture<http::Response *> future) { QEventLoop loop; // Interrrupt the event loop when the result is available QFutureWatcher<http::Response *> watcher; watcher.setFuture(future); loop.connect(&watcher, SIGNAL(finished()), SLOT(quit())); // Prevent infinite loop if the future completes before we start the loop QTimer timer; loop.connect(&timer, SIGNAL(timeout()), SLOT(quit())); timer.setSingleShot(false); timer.start(1000); // Process events while waiting so that the UI stays responsive while(!future.isFinished()) { loop.exec(); } http::Response * response = future.result(); if(response->ok()) { m_lastErrorString.clear(); } else if(!response->error().empty()) { m_lastErrorString = toQString(response->error()); } else if(!response->data().empty()) { m_lastErrorString = toQString(response->data()); } else { m_lastErrorString = "HTTP Error " + QString::number(response->status()); } return response; }
void JamendoService::DownloadDirectoryFinished() { QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender()); Q_ASSERT(reply); app_->task_manager()->SetTaskFinished(load_database_task_id_); load_database_task_id_ = 0; // TODO: Not leak reply. QtIOCompressor* gzip = new QtIOCompressor(reply); gzip->setStreamFormat(QtIOCompressor::GzipFormat); if (!gzip->open(QIODevice::ReadOnly)) { qLog(Warning) << "Jamendo library not in gzip format"; delete gzip; return; } load_database_task_id_ = app_->task_manager()->StartTask(tr("Parsing Jamendo catalogue")); QFuture<void> future = QtConcurrent::run(this, &JamendoService::ParseDirectory, gzip); QFutureWatcher<void>* watcher = new QFutureWatcher<void>(); watcher->setFuture(future); connect(watcher, SIGNAL(finished()), SLOT(ParseDirectoryFinished())); }
QPixmap CoverArtCache::requestCover(const CoverInfo& requestInfo, const QObject* pRequestor, int requestReference, const int desiredWidth, const bool onlyCached, const bool signalWhenDone) { if (sDebug) { qDebug() << "CoverArtCache::requestCover" << requestInfo << pRequestor << requestReference << desiredWidth << onlyCached << signalWhenDone; } if (requestInfo.type == CoverInfo::NONE) { if (signalWhenDone) { emit(coverFound(pRequestor, requestReference, requestInfo, QPixmap(), true)); } return QPixmap(); } // keep a list of trackIds for which a future is currently running // to avoid loading the same picture again while we are loading it QPair<const QObject*, int> requestId = qMakePair(pRequestor, requestReference); if (m_runningRequests.contains(requestId)) { return QPixmap(); } // If this request comes from CoverDelegate (table view), it'll want to get // a cropped cover which is ready to be drawn in the table view (cover art // column). It's very important to keep the cropped covers in cache because // it avoids having to rescale+crop it ALWAYS (which brings a lot of // performance issues). QString cacheKey = CoverArtUtils::pixmapCacheKey(requestInfo.hash, desiredWidth); QPixmap pixmap; if (QPixmapCache::find(cacheKey, &pixmap)) { if (signalWhenDone) { emit(coverFound(pRequestor, requestReference, requestInfo, pixmap, true)); } return pixmap; } if (onlyCached) { if (sDebug) { qDebug() << "CoverArtCache::requestCover cache miss"; } return QPixmap(); } m_runningRequests.insert(requestId); QFutureWatcher<FutureResult>* watcher = new QFutureWatcher<FutureResult>(this); QFuture<FutureResult> future = QtConcurrent::run( this, &CoverArtCache::loadCover, requestInfo, pRequestor, requestReference, desiredWidth, signalWhenDone); connect(watcher, SIGNAL(finished()), this, SLOT(coverLoaded())); watcher->setFuture(future); return QPixmap(); }
int ServerListener::run() { QFuture<int> future = QtConcurrent::run(this, &ServerListener::concurrentServerListener); QFutureWatcher<int> watcher; watcher.setFuture(future); return 0; }
void tst_QFutureWatcher::resultAt() { QFutureWatcher<int> futureWatcher; futureWatcher.setFuture((new IntTask())->start()); futureWatcher.waitForFinished(); QCOMPARE(futureWatcher.result(), 10); QCOMPARE(futureWatcher.resultAt(0), 10); }
void MainWindow::LoadFile() { if (FileFormatPluginList.size()) { QString FileName = QFileDialog::getOpenFileName(this, tr("Open File"), "", FileFormatPluginList[0]->getFormatDescription()); //test(); // Create a progress dialog. QProgressDialog dialog; dialog.setLabelText(QString("Загрузка данных из файла")); // Create a QFutureWatcher and connect signals and slots. QFutureWatcher<void> futureWatcher; QTimer timer; connect(&timer, SIGNAL(timeout()), this, SLOT(updateProgress())); timer.start(1000); QObject::connect(&futureWatcher, SIGNAL(finished()), &dialog, SLOT(reset())); QObject::connect(&dialog, SIGNAL(canceled()), SLOT(cancelOperation())); QObject::connect(&dialog, SIGNAL(canceled()), &futureWatcher, SLOT(cancel())); QObject::connect(this, SIGNAL(progressValueChanged(int)), &dialog, SLOT(setValue(int))); //extern void FileFormatPluginList[0]->getDataFromChannel(channel,(qint8*)data); QFuture<void> future = QtConcurrent::run(FileFormatPluginList[0], &FileReadInterface::LoadFile, FileName); // Start the computation. futureWatcher.setFuture(future); // Display the dialog and start the event loop. dialog.exec(); futureWatcher.waitForFinished(); dialog.setValue(100); dialog.hide(); timer.stop(); cube= FileFormatPluginList[0]->getCube(); QList<double> list = cube->GetListOfChannels(); foreach(double l , list) { ui->ChannelListWidget->addItem(QString("%1").arg(l)); }
void KWin::Script::run() { if (running() || m_starting) { return; } m_starting = true; QFutureWatcher<QByteArray> *watcher = new QFutureWatcher<QByteArray>(this); connect(watcher, SIGNAL(finished()), SLOT(slotScriptLoadedFromFile())); watcher->setFuture(QtConcurrent::run(this, &KWin::Script::loadScriptFromFile)); }
/* WorkSheetModel *Fix8Log::readLogFile(const QString &fileName,QString &errorStr) { bool bstatus; msg_type mt; // msg_seq_num snum; QString str; QString name; QMap <QLatin1String, qint32> senderMap; // <sender id, numofoccurances> TEX::SenderCompID scID; //TEX::TargetCompID tcID; TEX::SendingTime sendTime; std::string sstr; QString qstr; QString seqNumStr; QString senderID; QFile dataFile(fileName); QList<QStandardItem *> itemList; WorkSheetModel *model = new WorkSheetModel(this); qDebug() << "HERE WE ARE IN READ LOG FILE " << __FILE__ << __LINE__; qApp->processEvents(QEventLoop::ExcludeSocketNotifiers,5); QList <GUI::ConsoleMessage> msgList; bstatus = dataFile.open(QIODevice::ReadOnly); if (!bstatus) { GUI::ConsoleMessage message(tr("Failed to open file: ") + fileName); msgList.append(message); delete model; return 0; } int i=0; QElapsedTimer myTimer; int linecount = 0; qint32 fileSize = dataFile.size(); QByteArray ba; while(!dataFile.atEnd()) { ba = dataFile.readLine(); linecount++; } dataFile.seek(0); model->setRowCount(linecount); int colPosition = 0; int rowPosition = 0; myTimer.start(); QMessageList *messageList = new QMessageList(); while(!dataFile.atEnd()) { itemList.clear(); try { msg_seq_num snum; sender_comp_id senderID; ba = dataFile.readLine(); ba.truncate(ba.size()-1); Message *msg = Message::factory(TEX::ctx(),ba.data()); msg->Header()->get(snum); msg->Header()->get(senderID); char c[60]; memset(c,'\0',60); senderID.print(c); QLatin1String sid(c); QMessage *qmessage = new QMessage(msg,sid,snum()); qDebug() << "SEQ NUM = " << snum() << "sid = " << sid << __FILE__ << __LINE__; if (senderMap.contains(sid)) { qint32 numOfTimes = senderMap.value(sid); numOfTimes++; senderMap.insert(sid,numOfTimes); } else senderMap.insert(sid,1); messageList->append(qmessage); } catch (f8Exception& e){ errorStr = "Error - Invalid data in file: " + fileName + ", on row: " + QString::number(i); qWarning() << "exception, row " << i; qWarning() << "Error - " << e.what(); msgList.append(GUI::ConsoleMessage(errorStr,GUI::ConsoleMessage::ErrorMsg)); } i++; } bool cancelLoad = false; model->setMessageList(messageList,cancelLoad); //nMilliseconds = myTimer.elapsed(); qstr = QString::number(model->rowCount()) + tr(" Messages were read from file: ") + fileName; //msgList.append(GUI::Message(qstr)); dataFile.close(); return model; } */ void Fix8Log::readFileInAnotherThread(const QString &fileName,QString &errorStr) { QFutureWatcher <FutureReadData *> *watcher = new QFutureWatcher <FutureReadData *>(); connect(watcher,SIGNAL(finished()),this,SLOT(finishedReadingDataFileSlot())); QFuture<FutureReadData *> future = QtConcurrent::run(readLogFileInThread,fileName,errorStr); watcher->setFuture(future); }
void Dialog::on_ProgramButton_clicked() { QFutureWatcher<void> watcher; QObject::connect(&watcher, SIGNAL(finished()), SLOT(ProgramThread_quit())); QFuture<void> future = QtConcurrent::run(this,ProgramThread_run); watcher.setFuture(future); return; }
void OtrInternal::create_privkey(const char *accountname, const char *protocol) { Q_ASSERT(m_userstate); if(!m_mutex.tryLock(10)) return; QMessageBox infoMb(QMessageBox::Information, tr("qutim-otr"), tr("Generating keys for account %1\nThis may take a while.\nPlease, move mouse and use keyoard to decrease generation time.").arg(QString(accountname)), QMessageBox::Ok, NULL, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint); infoMb.button(QMessageBox::Ok)->setEnabled(false); infoMb.button(QMessageBox::Ok)->setText(tr("please wait...")); infoMb.setWindowModality(Qt::NonModal); infoMb.setModal(false); infoMb.show(); Protocol *protocolObject = Protocol::all().value(QString::fromUtf8(protocol)); Account *account = protocolObject->account(QString::fromUtf8(accountname)); OTRCrypt::instance()->disableAccount(account); { QByteArray keysFile = m_keysFile.toLocal8Bit(); QEventLoop loop; QFutureWatcher<gcry_error_t> watcher; connect(&watcher, SIGNAL(finished()), &loop, SLOT(quit())); QFuture<gcry_error_t> future = QtConcurrent::run(otrl_privkey_generate, m_userstate, keysFile.constData(), accountname, protocol); watcher.setFuture(future); loop.exec(); } OTRCrypt::instance()->enableAccount(account); m_mutex.unlock(); infoMb.button(QMessageBox::Ok)->setEnabled(true); infoMb.button(QMessageBox::Ok)->setText("Ok"); char fingerprint[45]; if (otrl_privkey_fingerprint(m_userstate, fingerprint, accountname, protocol) == NULL) { QMessageBox failMb(QMessageBox::Critical, tr("qutim-otr"), tr("Failed to generate key for account %1\nThe OTR Plugin will not work.").arg(QString(accountname)), QMessageBox::Ok, NULL, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint); failMb.exec(); } else { infoMb.setText(tr("The fingerprint for account %1 is\n").arg(QString(accountname)) + QString(fingerprint)); } infoMb.exec(); }
void DeviceProperties::UpdateFormats() { QString id = index_.data(DeviceManager::Role_UniqueId).toString(); DeviceLister* lister = manager_->GetLister(index_.row()); std::shared_ptr<ConnectedDevice> device = manager_->GetConnectedDevice(index_.row()); // Transcode mode MusicStorage::TranscodeMode mode = MusicStorage::TranscodeMode( index_.data(DeviceManager::Role_TranscodeMode).toInt()); switch (mode) { case MusicStorage::Transcode_Always: ui_->transcode_all->setChecked(true); break; case MusicStorage::Transcode_Never: ui_->transcode_off->setChecked(true); break; case MusicStorage::Transcode_Unsupported: default: ui_->transcode_unsupported->setChecked(true); break; } // If there's no lister then the device is physically disconnected if (!lister) { ui_->formats_stack->setCurrentWidget(ui_->formats_page_not_connected); ui_->open_device->setEnabled(false); return; } // If there's a lister but no device then the user just needs to open the // device. This will cause a rescan so we don't do it automatically. if (!device) { ui_->formats_stack->setCurrentWidget(ui_->formats_page_not_connected); ui_->open_device->setEnabled(true); return; } if (!updating_formats_) { // Get the device's supported formats list. This takes a long time and it // blocks, so do it in the background. supported_formats_.clear(); QFuture<bool> future = QtConcurrent::run(std::bind( &ConnectedDevice::GetSupportedFiletypes, device, &supported_formats_)); QFutureWatcher<bool>* watcher = new QFutureWatcher<bool>(this); watcher->setFuture(future); connect(watcher, SIGNAL(finished()), SLOT(UpdateFormatsFinished())); ui_->formats_stack->setCurrentWidget(ui_->formats_page_loading); updating_formats_ = true; } }
FutureProgress *ProgressManagerPrivate::doAddTask(const QFuture<void> &future, const QString &title, Id type, ProgressFlags flags) { // watch QFutureWatcher<void> *watcher = new QFutureWatcher<void>(); m_runningTasks.insert(watcher, type); connect(watcher, &QFutureWatcherBase::progressRangeChanged, this, &ProgressManagerPrivate::updateSummaryProgressBar); connect(watcher, &QFutureWatcherBase::progressValueChanged, this, &ProgressManagerPrivate::updateSummaryProgressBar); connect(watcher, &QFutureWatcherBase::finished, this, &ProgressManagerPrivate::taskFinished); watcher->setFuture(future); // handle application task if (flags & ShowInApplicationIcon) { if (m_applicationTask) disconnectApplicationTask(); m_applicationTask = watcher; setApplicationProgressRange(future.progressMinimum(), future.progressMaximum()); setApplicationProgressValue(future.progressValue()); connect(m_applicationTask, &QFutureWatcherBase::progressRangeChanged, this, &ProgressManagerPrivate::setApplicationProgressRange); connect(m_applicationTask, &QFutureWatcherBase::progressValueChanged, this, &ProgressManagerPrivate::setApplicationProgressValue); setApplicationProgressVisible(true); } // create FutureProgress and manage task list removeOldTasks(type); if (m_taskList.size() == 10) removeOneOldTask(); FutureProgress *progress = new FutureProgress; progress->setTitle(title); progress->setFuture(future); m_progressView->addProgressWidget(progress); m_taskList.append(progress); progress->setType(type); if (flags.testFlag(ProgressManager::KeepOnFinish)) progress->setKeepOnFinish(FutureProgress::KeepOnFinishTillUserInteraction); else progress->setKeepOnFinish(FutureProgress::HideOnFinish); connect(progress, &FutureProgress::hasErrorChanged, this, &ProgressManagerPrivate::updateSummaryProgressBar); connect(progress, &FutureProgress::removeMe, this, &ProgressManagerPrivate::slotRemoveTask); connect(progress, &FutureProgress::fadeStarted, this, &ProgressManagerPrivate::updateSummaryProgressBar); connect(progress, &FutureProgress::statusBarWidgetChanged, this, &ProgressManagerPrivate::updateStatusDetailsWidget); updateStatusDetailsWidget(); emit taskStarted(type); return progress; }