0

私は問題があります。Abort()を呼び出すと、complexMathインスタンスにクリーンアップを行うのに十分な時間がなくても、run関数が返されます。

私が欲しいのは、Abort()を呼び出した後、complexMathインスタンスがそれ自体をシャットダウンするのに十分な時間があることです。これにより、保留中のすべての信号とスロット(complexMath内では、独自の信号とスロットもあります)がクリアされてから戻ります。

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;
}

ありがとう!

4

1 に答える 1

0

stopNow シグナルを取り除くことができると思います:

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();
}
于 2010-08-16T19:27:15.770 に答える