码迷,mamicode.com
首页 > 编程语言 > 详细

Qt5线程错误:QThread: Destroyed while thread is still running(执行runThread->exit(0))

时间:2019-03-26 01:30:25      阅读:914      评论:0      收藏:0      [点我收藏+]

标签:一个   错误   开启   exit   作者   原创文章   .net   链接   函数   

背景:

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

        新建一个子线程类,编写槽函数和信号,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;
---------------------
作者:爱因
来源:CSDN
原文:https://blog.csdn.net/xbnlkdbxl/article/details/76828071
版权声明:本文为博主原创文章,转载请附上博文链接!

Qt5线程错误:QThread: Destroyed while thread is still running(执行runThread->exit(0))

标签:一个   错误   开启   exit   作者   原创文章   .net   链接   函数   

原文地址:https://www.cnblogs.com/findumars/p/10597592.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!