2010-08-16 8 views
0

J'ai un problème. Si j'appelle Abort(), la fonction d'exécution retournera sans que l'instance de complexeMath ait assez de temps pour faire le nettoyage. Ce que je veux, après avoir appelé Abort(), l'instance de complexeMath a assez de temps pour s'arrêter, effaçant tous les signaux et slots en attente (à l'intérieur de complexeMath, il a aussi son propre signal et slots) avant son retour.Nettoyez QThread après avoir appelé quit()

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

Merci!

Répondre

0

Je pense que vous pouvez vous débarrasser du signal 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(); 
} 
Questions connexes