0

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?

1
Contributor
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Zolookas
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.