How to run a timer inside a QThread?

前端 未结 4 1364
长情又很酷
长情又很酷 2020-12-30 15:52

I would like to run a timer inside a QThread. I have written some code in which i am getting some error during the run time. Please guide me into the right direction. What a

4条回答
  •  醉梦人生
    2020-12-30 16:13

    Your timer does not belong to your thread. You should create it in your run() method or you should call tmer->moveToThread before connecting it to slots, but after thread was started.

    Check it: MyThread belongs to your main thread. You create timer in constructor of MyThread - so timer belongs to main thread too. But you are trying to initialize and use it in ::run method, that belongs to other thread.

提交回复
热议问题