QThread的源码(直接搜索"thread.cpp"即可,或者在github里搜)
Posted 朝闻道
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了QThread的源码(直接搜索"thread.cpp"即可,或者在github里搜)相关的知识,希望对你有一定的参考价值。
void QThread::run() { (void) exec(); } int QThread::exec() { Q_D(QThread); QMutexLocker locker(&d->mutex); d->data->quitNow = false; if (d->exited) { d->exited = false; return d->returnCode; } locker.unlock(); QEventLoop eventLoop; int returnCode = eventLoop.exec(); locker.relock(); d->exited = false; d->returnCode = -1; return returnCode; } void QThread::exit(int returnCode) { Q_D(QThread); QMutexLocker locker(&d->mutex); d->exited = true; d->returnCode = returnCode; d->data->quitNow = true; for (int i = 0; i < d->data->eventLoops.size(); ++i) { QEventLoop *eventLoop = d->data->eventLoops.at(i); eventLoop->exit(returnCode); } } /*! Tells the thread‘s event loop to exit with return code 0 (success). Equivalent to calling QThread::exit(0). This function does nothing if the thread does not have an event loop. \sa exit(), QEventLoop */ void QThread::quit() { exit(); }
https://github.com/openwebos/qt/blob/master/src/corelib/thread/qthread.cpp
以上是关于QThread的源码(直接搜索"thread.cpp"即可,或者在github里搜)的主要内容,如果未能解决你的问题,请参考以下文章