Hi,
I'm having problems with QtConcurrent, how to pause execution of QtConcurrent function (thread) ?
I've tried QFuture setPaused(true) and pause() but that does not work. Let say I have code like this:
void MainWindow::on_pushButton_clicked() // run button
{
future = QtConcurrent::run(this, &MainWindow::my_func);
watcher.setFuture(future);
}
void MainWindow::on_pushButton_2_clicked() //pause button
{
future.pause();
return;
}
void MainWindow::my_func()
{
qDebug()<< "time-consuming code start";
for (int i = 0; i < 8000; i++)
{
for (int j = 1; j< 1000; j++)
{
sum = sum * i / j;
}
}
qDebug()<< "time-consuming code end";
}
void MainWindow::on_pushButton_clicked() // run button
{
future = QtConcurrent::run(this, &MainWindow::my_func);
watcher.setFuture(future);
}
void MainWindow::on_pushButton_2_clicked() //pause button
{
future.pause();
return;
}
void MainWindow::my_func()
{
qDebug()<< "time-consuming code start";
for (int i = 0; i < 8000; i++)
{
for (int j = 1; j< 1000; j++)
{
sum = sum * i / j;
QApplication::processEvents();
}
}
qDebug()<< "time-consuming code end";
}
To copy to clipboard, switch view to plain text mode
When I press pause button my_func() still continues, thread is not paused. what am I doing wrong, how to pause execution of my_func ?
Thanks in advance.
Bookmarks