Frage

Ich habe ein Problem. Wenn ich Abort () aufrufen, wird Lauf-Funktion zurück, ohne complexMath Instanz haben genug Zeit, aufzuräumen zu tun.

Was ich will, ist, nach dem Aufruf von Abort (), complexMath Instanz haben genug Zeit zum Herunterfahren selbst, Clearing alle anstehenden Signal und Schlitz (innen complexMath es auch eigenes Signal und Slots), bevor es zurück.

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

Danke!

War es hilfreich?

Lösung

ich glaube, Sie loszuwerden, das StopNow Signal bekommen können:

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();
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top