for (int id=1;id<=guidata.numbers_of_workerthreads;id++)
{
Worker *worker = new Worker(&guidata,ui,id,&m_c,&mutex_file,&mutex_count);
worker->moveToThread(thread);
//connect events from worker<-> threads
connect(worker,
SIGNAL(error
(QString)),
this,
SLOT(errorString
(QString)));
connect(thread, SIGNAL(started()), worker, SLOT(comets_to_use()));
connect(this, SIGNAL(shut_down_threads()), worker ,SLOT(on_shut_down_threads())); //<--- how im trying to access thread/worker from gui
connect(worker, SIGNAL(finished()), thread, SLOT(quit()));
connect(worker, SIGNAL(finished()), worker, SLOT(deleteLater()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
thread->start();
}
}
for (int id=1;id<=guidata.numbers_of_workerthreads;id++)
{
QThread *thread = new QThread;
Worker *worker = new Worker(&guidata,ui,id,&m_c,&mutex_file,&mutex_count);
worker->moveToThread(thread);
//connect events from worker<-> threads
connect(worker, SIGNAL(error(QString)), this, SLOT(errorString(QString)));
connect(thread, SIGNAL(started()), worker, SLOT(comets_to_use()));
connect(this, SIGNAL(shut_down_threads()), worker ,SLOT(on_shut_down_threads())); //<--- how im trying to access thread/worker from gui
connect(worker, SIGNAL(finished()), thread, SLOT(quit()));
connect(worker, SIGNAL(finished()), worker, SLOT(deleteLater()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
thread->start();
}
}
To copy to clipboard, switch view to plain text mode
//stop button
void MainWindow::on_pushButton_9_clicked()
{
qDebug() << "shutdown emitted";
emit shut_down_threads();
//stop button
void MainWindow::on_pushButton_9_clicked()
{
qDebug() << "shutdown emitted";
emit shut_down_threads();
To copy to clipboard, switch view to plain text mode
void Worker::on_shut_down_threads()
{
qDebug
() <<
"terminating thread " <<
QString::number(thread_id
);
QThread::currentThread()->terminate
();
}
void Worker::on_shut_down_threads()
{
qDebug() << "terminating thread " << QString::number(thread_id);
QThread::currentThread()->terminate();
}
To copy to clipboard, switch view to plain text mode
Bookmarks