Quote Originally Posted by N3wb View Post
Why is there difference between having the loop in the "run()" or "exec()" functions, though? It's the same code in both functions, but for some reason only works in the "exec()" function?

Thanks!
There is nothing difference. Here is code of original QThread::exec method :
Qt Code:
  1. int QThread::exec()
  2. {
  3. Q_D(QThread);
  4. QMutexLocker locker(&d->mutex);
  5. d->data->quitNow = false;
  6. QEventLoop eventLoop;
  7. locker.unlock();
  8. int returnCode = eventLoop.exec();
  9. return returnCode;
  10. }
To copy to clipboard, switch view to plain text mode 
As You see You never create and exec event loop. Yours Thread class must be defined something like that :
Qt Code:
  1. class Thread : public QThread
  2. {
  3. Q_OBJECT
  4.  
  5. public:
  6. Thread();
  7. signals:
  8. void testSignal(QString message);
  9. slots:
  10. void mTimeOut();
  11. protected:
  12. void run();
  13. };
  14.  
  15. Thread::Thread()
  16. {
  17. }
  18.  
  19. void Thread::run()
  20. {
  21. QTimer::singleShot(0, this, SLOT(mTimeOut()));
  22.  
  23. exec();
  24. }
  25.  
  26. void Thread::mTimeOut()
  27. {
  28. //do what You need in one step
  29. emit(testSignal("hello world!"));
  30. //do sleep and after start next step
  31. QTimer::singleShot(1, this, SLOT(mTimeOut()));
  32. }
To copy to clipboard, switch view to plain text mode