Greetings.
I am trying to understand the concept behind using threads and have subclassed QThread the following way:

Qt Code:
  1. // Header:
  2.  
  3. #include <QtDebug>
  4.  
  5. class TestThread : public QThread
  6. {
  7. public:
  8. void run();
  9. };
  10.  
  11. // C++ source:
  12.  
  13. void TestThread::run() {
  14. qDebug() << "Message from thread";
  15. exec();
  16. }
  17.  
  18. // main.cpp:
  19.  
  20. #include "testthread.h"
  21.  
  22. int main(int argc, char** argv) {
  23. TestThread t1, t2;
  24. t1.start();
  25. t2.start();
  26. qDebug() << "Message from main function";
  27. return 0;
  28. }
To copy to clipboard, switch view to plain text mode 
It returns 2 warnings QThread: Destroyed while thread is still running warning
and then it crashes.
However, if I replace
Qt Code:
  1. TestThread t1,t2;
To copy to clipboard, switch view to plain text mode 
with
Qt Code:
  1. TestThread *t1 = new TestThread, *t2 = new TestThread;
To copy to clipboard, switch view to plain text mode 
it works. My question is: why?