I would like to cancel a QtConcurent::map computation at an event.
This is my test code (the computation is represented by an infinite loop) :
class Test : public QObject
{
Q_OBJECT
public:
Test(QObject *parent=0) : QObject(parent){}
void test()
{
qDebug() << tr("thread:") << QThread::currentThread();
//computation
while(true);
}
};
I have a list of Test, and I do :
//QFuture<void> m_concurentResult;
m_concurentResult = QtConcurrent::map(m_collection, &Test::test);
//That's Ok, I have the two outputs :
// QThread(0x4e21f8, name = "Thread (pooled)")
// QThread(0x4e21b8, name = "Thread (pooled)")
The goal is to cancel all the computation when the user click a button.
void Widget::on_pushButton_clicked()
{
m_concurentResult.cancel();
m_concurentResult.waitForFinished();
}
But when I click the button, the UI is freezed, and nothing is done. Thank's for help !