QApplication app(argc, argv); QThread thread; thread.start(); thread.exit(); thread.wait(); return 0;
int main(int argc, char *argv[]){ QApplication app(argc, argv); QThread thread; thread.start(); do thread.exit(); while (!thread.wait(0)); return 0;}
int main(int argc, char *argv[]){ QApplication app(argc, argv); QThread thread; thread.start(); { QObject* dummy = new QObject; dummy->moveToThread(&thread); QMetaObject::invokeMethod(dummy, "deleteLater", Qt::BlockingQueuedConnection, QGenericArgument(), Q_ARG(QObject*, dummy)); } thread.exit(); thread.wait(); return 0;}
{ QObject* dummy = new QObject; dummy->moveToThread(&thread); QMetaObject::invokeMethod(dummy, "deleteLater", Qt::BlockingQueuedConnection, QGenericArgument(), Q_ARG(QObject*, dummy)); }
void QThread::exit(int returnCode){ Q_D(QThread); QMutexLocker locker(&d->mutex); d->data->quitNow = true; for (int i = 0; i < d->data->eventLoops.size(); ++i) { QEventLoop *eventLoop = d->data->eventLoops.at(i); eventLoop->exit(returnCode); }}
class Thread : public QThread{public: void run() { sleep( 2 ); qDebug( "exec" ); exec(); }};int main(int argc, char *argv[]){ QApplication app(argc, argv); Thread thread; thread.start(); qDebug( "start" ); thread.exit(); qDebug( "exit" ); thread.wait(); return 0;}