-
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();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)