2 つのクラスがあります。1 つはメイン スレッドで実行されて GUI 操作を実行し、もう 1 つは計算を実行してネットワーク リクエストを作成します。
// A member of the class that runs in the main thread
QThread thread;
以下は、メイン スレッドで実行されるクラスの初期化メソッドの抜粋です。
// 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();
メインスレッドで実行されるクラスのデストラクタで:
if(thread.isRunning())
{
thread.quit();
thread.wait();
}
私が期待しているのは、スレッドが終了し、CServerThread
クラスのインスタンスを破棄することです。ただし、CServerThread
クラスのデストラクタは呼び出されていません。