QMutex“A mutex must be unlocked in the same thread that locked it”解决(在run里创建对象是不二法宝)

多线程时出现如下警告信息:

A mutex must be unlocked in the same thread that locked it;

原因可能有二:

1.创建QMutex不在当前线程;

2.QWaitCondition::wait 调用前没有调用QMutex::lock;

 

解决方法:

1.在run函数中创建QMutex;

 

...

m_pMutex = new QMutex();

...

 

2.wait前调用lock:

 

QMutexLocker locker(m_pMutex);

 m_waitCond.wait(m_pMutex);

https://blog.csdn.net/lanhy999/article/details/8657359

原文地址:https://www.cnblogs.com/findumars/p/9524987.html