Qt5线程错误:QThread: Destroyed while thread is still running

背景:

        当前类,编写接收子线程类信号的槽函数和触发子线程类执行的信号;

        新建一个子线程类,编写槽函数和信号,MyClass *m_MyClass=new MyClass();

        新建一个线程对象QThread *runThread=new QThread();

        使用connect连接当前类与子线程的信号槽,以便触发线程及接收线程执行结果;

        使用m_MyClass.moveToThread(runThread),将子线程类移到线程中执行;

        runThread->start(),开启线程。


**在当前线程的析构函数中,如果先删除runThread再删除m_MyClass,则会出现错误QThread: Destroyed while thread is still running

**正确的写法应该是:

   runThread->exit(0);

   delete m_MyClass;

   delete runThread;


评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值