Quote Originally Posted by wysota
Qt Code:
  1. while(eThread.isRunning())
  2. usleep(100);
To copy to clipboard, switch view to plain text mode 

But what is this for? It stops the main thread. And if so, why do you need another thread? You can move its functionality to the main thread and the result will be identical. Better yet, you can split the work you do in the other thread into smaller chunks and use a QTimer with 0 interval to trigger next steps of the process and you'll gain this, that you won't block the event handling and your gui will remain responsive.


"Common" doesn't mean "proper". You can achieve the same without using a separate thread which only slows down the process.
I have rewrote the code. My previous msg is in accordans with these fragments:

Starting a thread:

Qt Code:
  1. ExcitThread* eThread = new ExcitThread(this, eInfo, this);
  2. eThread->start(QThread::LowestPriority);
To copy to clipboard, switch view to plain text mode 

QThread implementation:

Qt Code:
  1. ExcitThread::ExcitThread(QObject* parent, const ExcitInfo& anInfo, QWidget* aFeedback) : QThread(parent) {
  2. this->info = anInfo;
  3. this->feedback = aFeedback;
  4. connect(this, SIGNAL(showStatus(const QString&)), this->feedback, SLOT(showStatus(const QString&)));
  5. connect(this, SIGNAL(showStatus(const QString&, int)), this->feedback, SLOT(showStatus(const QString&, int)));
  6. connect(this, SIGNAL(showCritical(const QString&)), this->feedback, SLOT(showCritical(const QString&)));
  7. }
  8.  
  9. void ExcitThread::run() {
  10. emit showStatus("Generating excitation...");
  11. try {
  12. Excitation::generate( this->info.workDir.toStdString(),
  13. this->info.duration,
  14. this->info.sampleRate,
  15. this->info.bitDepth,
  16. this->info.minFreq,
  17. this->info.maxFreq
  18. );
  19. } catch(QLE e) {
  20. emit showCritical(e.msg.c_str());
  21. emit showStatus("Excitation generating failed!", 2000);
  22. return;
  23. }
  24. emit showStatus("Excitation and inverse filter are generated!", 2000);
  25. }
To copy to clipboard, switch view to plain text mode 

That "while" was with the aim to understand how all this works :-)