Is it safe to call QThread::start() many times?
-
Hi,
Is it safe to quit and start the same QThread many times like this:
QObject::connect(this, &MainWindow::doSomething, worker, &Worker::doSomething); .... void MainWindow::on_pushButton_clicked() // cancel { thread->requestInterruption(); thread->quit(); thread->wait(); } void MainWindow::on_pushButton_2_clicked() // start { thread->start(); emit doSomething(); }
?
-
Hi,
Is it safe to quit and start the same QThread many times like this:
QObject::connect(this, &MainWindow::doSomething, worker, &Worker::doSomething); .... void MainWindow::on_pushButton_clicked() // cancel { thread->requestInterruption(); thread->quit(); thread->wait(); } void MainWindow::on_pushButton_2_clicked() // start { thread->start(); emit doSomething(); }
?
-
Hi,
Is it safe to quit and start the same QThread many times like this:
QObject::connect(this, &MainWindow::doSomething, worker, &Worker::doSomething); .... void MainWindow::on_pushButton_clicked() // cancel { thread->requestInterruption(); thread->quit(); thread->wait(); } void MainWindow::on_pushButton_2_clicked() // start { thread->start(); emit doSomething(); }
?
@qwe3 said in Is it safe to call QThread::start() many times?:
void MainWindow::on_pushButton_2_clicked() // start
{
thread->start();
emit doSomething();
}You could replace this with a connection to
connect(thread, &QThread::started, worker, &Worker::DoWork)
Then start the thread when needed.
@qwe3 said in Is it safe to call QThread::start() many times?:
thread->requestInterruption();
Do you handle this properly?
-
-
@qwe3 said in Is it safe to call QThread::start() many times?:
if(QThread::currentThread()->isInterruptionRequested())
{
return;
}Looks good.