1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| WorkObject * workObject = new WorkObject(); QThread * workThread = new QThread();
workObject->moveToThread(workThread);
QObject::connect(workThread, &QThread::started, workObject, &WorkObject::starWork);
QObject::connect(workObject, &WorkObject::workFinished, workThread, [=]() { workThread->quit(); workThread->wait(); });
QObject::connect(workThread, &QThread::finished, workObject, &WorkObject::deleteLater);
QObject::connect(workObject, &WorkObject::destroyed, workThread, &QThread::deleteLater);
QObject::connect(workThread, &QThread::destroyed, [&]() { qDebug() << "workThread 销毁" << endl; });
workThread->start();
|