2010-08-16 4 views
0

문제가 있습니다. Abort()를 호출하면 실행 함수는 complexMath 인스턴스가 정리를 수행 할 충분한 시간없이 반환합니다.전화를 건 후에 QThread를 정리하십시오.

내가 원하는 것은, 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; 
} 

감사!

답변

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