I execute in a Qthread an image processing procedure taking around 3 hours without the possibility to put some check points inside it for a exit gate. The problem is I cannot stop it. This code represents this problem :
Qt Code:
  1. class Toto : public QObject
  2. {
  3. Q_OBJECT
  4. public slots:
  5. void exec(){
  6. //I represent the real process with an infinite loop
  7. while(1==1);
  8. }
  9. };
  10. int main(int argc, char *argv[])
  11. {
  12. QApplication aa(argc, argv);
  13. QThread * t1 = new QThread;
  14. Toto * toto1 = new Toto;
  15. QThread * t2 = new QThread;
  16. Toto * toto2 = new Toto;
  17. push.show();
  18. toto1->moveToThread(t1);
  19. toto2->moveToThread(t2);
  20. QMetaObject::invokeMethod(toto1, "exec", Qt::QueuedConnection);
  21. QMetaObject::invokeMethod(toto2, "exec", Qt::QueuedConnection);
  22. QApplication::connect(&push, SIGNAL(pressed()), t1,SLOT(terminate()), Qt::QueuedConnection);
  23. QApplication::connect(&push, SIGNAL(pressed ()), t2,SLOT(terminate()), Qt::QueuedConnection);
  24. t2->start();
  25. t1->start();
  26. return aa.exec();
  27. }
To copy to clipboard, switch view to plain text mode 
The problem is my infinite loop is not interrupted when I press the buttom.
Do you have any idea to solve this problem?
Thanks,
Vincent