Waiting QMutex claims

I found that even just waiting for QMutex will trigger a statement. What can i do wrong?

QMutex mutex; SyncMgr::SyncMgr(QObject *parent) : QObject(parent) { moveToThread( &thread ); thread.start(); process = new QProcess( this); connect( process, SIGNAL(readyReadStandardOutput()), this, SLOT(onReadyReadStandardOutput() ) ); connect( process, SIGNAL(readyReadStandardError()), this, SLOT(onReadyReadStandardError() ) ); } SyncMgr::~SyncMgr() { delete process; } void SyncMgr::onConnected() { cmdDispatcher.sendGetSerialNo(); // this asserts waitForResponse.wait( &mutex ); // waitForResponse is CWaitCondition object // ... } 

I get assert and error message:

ASSERT: 'copy' in stream \ qmutex.cpp, line 525

+5
source share
1 answer

You need to lock the mutexes before calling waitForResponse.wait (). The SyncMgr :: onConnected () method should look like this:

 void SyncMgr::onConnected() { cmdDispatcher.sendGetSerialNo(); mutex.lock(); waitForResponse.wait( &mutex ); // do something mutex.unlock(); ... } 

You can find more information here: http://doc.qt.io/qt-5/qwaitcondition.html#wait

0
source

All Articles