bool MainWindow::stopScan(){if (thread){ thread->terminate(); thread->wait(500); qDebug("Thread terminated"); delete thread;}}
MainWindow::MainWindow{ thread = new ScanThread(this);}void MainWindow::scanVocabulary(void){ if (thread) { thread->start(QThread::NormalPriority); ui->pushButtonStart->setDisabled(true); ui->pushButtonStop->setDisabled(false); qDebug("scanVocabulary: Scan thread started"); }}void MainWindow::stopScan(){ if (thread) { thread->exit(0); thread->deleteLater(); ui->pushButtonStart->setDisabled(false); ui->pushButtonStart->setChecked(false); }}ScanThread::~ScanThread(){ if (!isRunning()) return; if (text.count()) { drv->beginTransaction(); query.addBindValue(text); query.execBatch(QSqlQuery::ValuesAsRows); le = query.lastError(); if (le.type() == QSqlError::NoError) drv->commitTransaction(); else qDebug() << "~ScanThread: [" << le.text() << "]"; query.finish(); } wait(500);}
thread->exit(0);thread->deleteLater();
thread->wait();delete thread;
void MainWindow::stopScan(){ if (thread) { thread->exit(0); thread->deleteLater(); ui->pushButtonStart->setDisabled(false); ui->pushButtonStart->setChecked(false); }}
ThreadClass * thrd = new ThreadClass();connect(thrd ,SIGNAL(finished()),thrd ,SLOT(deleteLater()));thrd->start();