Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QFutureWatcher not work in for(;;) loop



  • Hi.
    QFutureWatcher not work in for(;;) loop.
    Without a loop, this code works, but in an for(;;) loop, the program stops and does nothing. Why so and how to fix it?

    int MainWindow::checkVector(QVector<int> vector, std::string sdtMd5String)
    {
        int result = 0;
        QFutureWatcher<void> futureWatcher;
        QEventLoop loop;
        connect ( this , &MainWindow::signalStopFuter, &futureWatcher, &QFutureWatcher<void>::cancel);
        futureWatcher.setFuture(QtConcurrent::map(vector,[&](const int& d){
            if(sdtMd5String == stdStringToMd5Hash(std::to_string(d))){
                qDebug()<<d<<QString::fromStdString(stdStringToMd5Hash(std::to_string(d)));
                result = d;
                signalStopFuter();
            }
        }));
        loop.exec();
        futureWatcher.waitForFinished();
        return result;
    }
    


  • it is work without QEventLoop loop;


Log in to reply