hey guys,

my app does calculations in backround threads which are contained in a worker object. The calculations performed are long and sometimes i will want to shut down the calculations and restart them. I wanted to let the main gui connect to the worker and tell it to terminate its current thread but somehow i cant get it to work.

from mainwindow.cpp:

creating threads and connecting them + start thread

Qt Code:
  1. for (int id=1;id<=guidata.numbers_of_workerthreads;id++)
  2. {
  3.  
  4. QThread *thread = new QThread;
  5.  
  6. Worker *worker = new Worker(&guidata,ui,id,&m_c,&mutex_file,&mutex_count);
  7.  
  8. worker->moveToThread(thread);
  9.  
  10. //connect events from worker<-> threads
  11. connect(worker, SIGNAL(error(QString)), this, SLOT(errorString(QString)));
  12. connect(thread, SIGNAL(started()), worker, SLOT(comets_to_use()));
  13. connect(this, SIGNAL(shut_down_threads()), worker ,SLOT(on_shut_down_threads())); //<--- how im trying to access thread/worker from gui
  14. connect(worker, SIGNAL(finished()), thread, SLOT(quit()));
  15. connect(worker, SIGNAL(finished()), worker, SLOT(deleteLater()));
  16. connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
  17.  
  18. thread->start();
  19. }
  20. }
To copy to clipboard, switch view to plain text mode 

this button is pressed to initiate the threads to shut down;

Qt Code:
  1. //stop button
  2. void MainWindow::on_pushButton_9_clicked()
  3. {
  4.  
  5. qDebug() << "shutdown emitted";
  6. emit shut_down_threads();
To copy to clipboard, switch view to plain text mode 

from worker.cpp:
(i know terminate is a bad practice this is just to get the initial shutdown to work)

Qt Code:
  1. void Worker::on_shut_down_threads()
  2. {
  3. qDebug() << "terminating thread " << QString::number(thread_id);
  4. QThread::currentThread()->terminate();
  5. }
To copy to clipboard, switch view to plain text mode 

sadly this is not stopping my calculations. Any pointers where i went wrong? im kinda lost! thx boys.