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

QThread: Destroyed while thread is still running

时间:2019-10-11 20:36:31      阅读:76      评论:0      收藏:0      [点我收藏+]

标签:bool   rup   details   调用   on()   isinf   ini   nbsp   vat   

Qt5已经分装了函数

void QThread::requestInterruption()
{
    Q_D(QThread);
    QMutexLocker locker(&d->mutex);
    if (!d->running || d->finished || d->isInFinish)
        return;
    if (this == QCoreApplicationPrivate::theMainThread) {
        qWarning("QThread::requestInterruption has no effect on the main thread");
        return;
    }
    d->interruptionRequested = true;
}
 
bool QThread::isInterruptionRequested() const
{
    Q_D(const QThread);
    QMutexLocker locker(&d->mutex);
    if (!d->running || d->finished || d->isInFinish) // 如果线程已经结束就。。。
        return false;
    return d->interruptionRequested;
}

在wile中用下面函数判断

while (!isInterruptionRequested())
{
     /////

     /////  
}

在析构函数中调用

ThreadToDisks:: ~ThreadToDisks()
{
    requestInterruption();
    quit();
    wait();
}

参考:https://blog.csdn.net/u013372900/article/details/80405261

 

QThread: Destroyed while thread is still running

标签:bool   rup   details   调用   on()   isinf   ini   nbsp   vat   

原文地址:https://www.cnblogs.com/herd/p/11656299.html

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