我有两个类——一个在主线程中运行并执行 GUI 操作,另一个执行一些计算并发出网络请求。
// 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
该类的析构函数没有被调用。