-
QThread *thread = new QThread( );
-
Task *task = new Task();
-
task->moveToThread(thread);
-
connect( thread, SIGNAL(started()), task, SLOT(doWork()) );
-
connect( task, SIGNAL(workFinished()), thread, SLOT(quit()) );//从Qt4.4开始,qthreads-no-longer-abstract,run 默认调用 QThread::exec(),即启动消息队列
-
//automatically delete thread and task object when work is done:
-
connect( thread, SIGNAL(finished()), task, SLOT(deleteLater()) );
-
connect( thread, SIGNAL(finished()), thread, SLOT(deleteLater()) );
-
thread->start();
如何释放”及QThread 的启动关闭
最新推荐文章于 2024-07-08 15:32:11 发布