码迷,mamicode.com
首页 > 其他好文 > 详细

QThread的源码(直接搜索"thread.cpp"即可,或者在github里搜)

时间:2017-01-17 23:03:58      阅读:288      评论:0      收藏:0      [点我收藏+]

标签:function   quit   oid   loop   thread   success   master   open   .exe   

 

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里搜)

标签:function   quit   oid   loop   thread   success   master   open   .exe   

原文地址:http://www.cnblogs.com/findumars/p/6294810.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!