In main loop there's GUI processing. In second thread - created inside QMainWindow constructor - I want to process data.
In specific point of time, in one of function in data thread - I want to display current process state and wait till user presses button (or timer expire - whatever). So I found QWaitCondition and QMutex which should do the job, but they only freeze program.
In data thread
extern QMutex robotNextMoveWaitMutex;
...
robotNextMoveWaitMutex.lock();
emit robotBeforeMove(¤tScanResult);
robotNextMoveWait.wait(&robotNextMoveWaitMutex);
robotNextMoveWaitMutex.unlock();
extern QWaitCondition robotNextMoveWait;
extern QMutex robotNextMoveWaitMutex;
...
robotNextMoveWaitMutex.lock();
emit robotBeforeMove(¤tScanResult);
robotNextMoveWait.wait(&robotNextMoveWaitMutex);
robotNextMoveWaitMutex.unlock();
To copy to clipboard, switch view to plain text mode
this signal is transmitted through series of object Robot->enviroment->experiment->DataThread to second thread MainWindow->Dialog
in Gui Thread
QMutex robotNextMoveWaitMutex;
...
QWaitCondition robotNextMoveWait;
QMutex robotNextMoveWaitMutex;
...
To copy to clipboard, switch view to plain text mode
In debug session I placed in all object in data thread slots with break point to watch how signal is processed. And it arrives to Experiment, but not to DataThread. Something strange.
Connections in DataThread is set like this
void CDataThread::run()
{
m_ptrExperiment = new CExperiment;
bool bResult;
bResult = connect(m_ptrExperiment,SIGNAL(robotBeforeMove(CScanResults *)),SLOT(onRobotBeforeMove(CScanResults *)));
Q_ASSERT_X(bResult==true,"CDataThread::run","Connect 'm_stExperiment:robotBeforeMove ' with 'this:onRobotBeforeMove'");
//bResult = connect(m_ptrExperiment,SIGNAL(robotBeforeMove(CScanResults *)),SIGNAL(robotBeforeMove(CScanResults *)));
//Q_ASSERT_X(bResult==true,"CDataThread::run","Connect 'm_stExperiment:robotBeforeMove ' with signal 'this:robotBeforeMove'");
exec();
}
void CDataThread::run()
{
m_ptrExperiment = new CExperiment;
bool bResult;
bResult = connect(m_ptrExperiment,SIGNAL(robotBeforeMove(CScanResults *)),SLOT(onRobotBeforeMove(CScanResults *)));
Q_ASSERT_X(bResult==true,"CDataThread::run","Connect 'm_stExperiment:robotBeforeMove ' with 'this:onRobotBeforeMove'");
//bResult = connect(m_ptrExperiment,SIGNAL(robotBeforeMove(CScanResults *)),SIGNAL(robotBeforeMove(CScanResults *)));
//Q_ASSERT_X(bResult==true,"CDataThread::run","Connect 'm_stExperiment:robotBeforeMove ' with signal 'this:robotBeforeMove'");
exec();
}
To copy to clipboard, switch view to plain text mode
Where did I make error? Could some one show me better solution? This is my second contact with threads.
Bookmarks