Hi, I am new to C++ and Qt and despite that i am thinking of using threads in my app. Here is an example code which outputs "." and then "QThread: Destroyed while thread is still running" error after pressing button.

class MyThread : public QThread
      {
          public:
              void run();
      };

      void MyThread::run()
      {
          while (true)
          {
              fprintf(stderr,".");
              sleep(5);
          }
      }

      void MainWindowImpl::on_button_clicked()
      {
          MyThread t;
          t.start();
      }

What can be wrong in this code? Am I not allowed to use while loop in thread?