0
두 개의 클래스가 있습니다. 하나는 주 스레드에서 실행되고 GUI 작업을 수행하고 다른 하나는 일부 계산을 수행하고 네트워크 요청을 수행합니다.이 클래스의 소멸자가 호출되지 않는 이유는 무엇입니까?
if(thread.isRunning())
{
thread.quit();
thread.wait();
}
: 메인 스레드에서 실행되는 클래스의 소멸자에서
// Create the class that runs in the other thread and move it there
CServerThread * server = new CServerThread;
server->moveToThread(&thread);
// When the thread terminates, we want the object destroyed
connect(&thread, SIGNAL(finished()), server, SLOT(deleteLater()));
thread.start();
: 여기
// A member of the class that runs in the main thread
QThread thread;
는 메인 스레드에서 실행되는 클래스의 초기화 방법에서 미리보기입니다
나는 스레드가 종료되고 CServerThread
클래스의 인스턴스를 파괴합니다. 그러나 CServerThread
클래스의 소멸자가 호출되지 않습니다.
설명 주셔서 감사합니다. 그러나'deleteLater()'는 내가 만든 QThread가 아니라 주 스레드의 컨텍스트에서 호출되는 것이 아니십니까? –
스레드가 'finished'신호를 내 보냅니다. 서버가 해당 스레드에 속해 있기 때문에 처리는 주 스레드가 아닌 스레드에서 수행됩니다. (맨 아래에있는 [here] (http://doc.qt.nokia.com/4.7/threads-qobject.html) 참조) 자동 연결 설명 – Mat
Qt :: DirectConnection을 사용하지 않으면 슬롯이 주 스레드에서 실행 되나요? 어떤 스레드가'finished()'신호를 내보내고 있습니까? –