hi, there
By clicking a button, I want to do heavy calculation several times in a loop and don't want them block the performance of the GUI, here is what I did. Although it did not block the GUI, it block the loop. How can I do it correct?

Somewhere in the GUI I have
Qt Code:
  1. for (int i = 1; i < 10; i++){
  2. cout<<"# "<<i<<endl;
  3. TrashThread trash(this, i);
  4. trash.start();
  5. }
To copy to clipboard, switch view to plain text mode 

For the TrashThread class, I have
Qt Code:
  1. TrashThread::TrashThread(QObject *parent, int i) : QThread(parent)
  2. {
  3. cout<<"thread "<<i<<endl;
  4. }
  5.  
  6. TrashThread::~TrashThread()
  7. {
  8. }
  9. void TrashThread::run()
  10.  
  11. {
  12. cout<<"sleep 5sec"<<endl;
  13. sleep(5);
  14. exec();
  15.  
  16. }
To copy to clipboard, switch view to plain text mode 
and here is the result
Qt Code:
  1. # 0
  2. thread 0
  3. sleep 5sec
  4. //the loop never goes to 2nd iteration
To copy to clipboard, switch view to plain text mode 
Thanks for help.
zl2k