首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在调用quit()后清理QThread

在调用quit()后清理QThread
EN

Stack Overflow用户
提问于 2010-08-16 15:32:11
回答 1查看 1.6K关注 0票数 0

我有个问题。如果我调用Abort(),run function将返回,而complexMath实例没有足够时间进行清理。

我想要的是,在调用Abort()之后,complexMath实例有足够的时间自行关闭,在返回之前清除所有挂起的信号和插槽(在complexMath内部,它也有自己的信号和插槽)。

代码语言:javascript
复制
void MyThread::Go(){
  start();
}

void MyThread::Abort(){
  emit stopNow();
  quit();
}

void MyThread::run(){
  ComplexMath * complexMath = new ComplexMath();
  connect( complexMath, SIGNAL(OnCalculation(qint)), this, SLOTS(PartialOutput(qint)) );
  connect( this, SIGNAL(stopNow()), complexMath, SLOTS(deleteLater());
  exec();
}

void MyThread::PartialOutput(qint data){
  qDebug() << data;
}

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-08-17 03:27:16

我认为你可以去掉stopNow信号:

代码语言:javascript
复制
void MyThread::Abort(){
  quit();
}

void MyThread::run(){
  ComplexMath * complexMath = new ComplexMath();
  connect( complexMath, SIGNAL(OnCalculation(qint)), this, SLOTS(PartialOutput(qint)) );
  exec();
  // Any code here will be run after the thread quits, and the event loop stops
  deleteLater();
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3491332

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档