c++qtqtconcurrent

Qtconcurrent - Easy way to start a second thread from gui thread


I would like to find an easy way to start a lengthy operation from my application's main gui thread. I have his exporter object that is not affiliated to any thread.

void closeExporter()
{  
    // Run closing of object in a different thread:
        QFuture<void> future = QtConcurrent::run([=]()
        {
            m_pExporter->close();
        });

        while (!future.isFinished())
        {
            QApplication::processEvents();
        //  QThread::msleep(0);
            qDebug() << "waiting!";
        }
}   

I am not using waitForFinished() function then it blocks any my gui thread becomes unresponsive. It works fine for a while put the debug printing stop and my application will still become unresponsive. Dies somebody have an idea why this is happening?


Solution

  • The original code was working fine after all. Sorry to burn your time.