T4ng10r
2nd May 2010, 13:44
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 QWaitCondition robotNextMoveWait;
extern QMutex robotNextMoveWaitMutex;
...
robotNextMoveWaitMutex.lock();
emit robotBeforeMove(¤tScanResult);
robotNextMoveWait.wait(&robotNextMoveWaitMutex);
robotNextMoveWaitMutex.unlock();
this signal is transmitted through series of object Robot->enviroment->experiment->DataThread to second thread MainWindow->Dialog
in Gui Thread
QWaitCondition robotNextMoveWait;
QMutex robotNextMoveWaitMutex;
...
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(CSc anResults *)),SLOT(onRobotBeforeMove(CScanResults *)));
Q_ASSERT_X(bResult==true,"CDataThread::run","Connect 'm_stExperiment:robotBeforeMove ' with 'this:onRobotBeforeMove'");
//bResult = connect(m_ptrExperiment,SIGNAL(robotBeforeMove(CSc anResults *)),SIGNAL(robotBeforeMove(CScanResults *)));
//Q_ASSERT_X(bResult==true,"CDataThread::run","Connect 'm_stExperiment:robotBeforeMove ' with signal 'this:robotBeforeMove'");
exec();
}
Where did I make error? Could some one show me better solution? This is my second contact with threads.
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 QWaitCondition robotNextMoveWait;
extern QMutex robotNextMoveWaitMutex;
...
robotNextMoveWaitMutex.lock();
emit robotBeforeMove(¤tScanResult);
robotNextMoveWait.wait(&robotNextMoveWaitMutex);
robotNextMoveWaitMutex.unlock();
this signal is transmitted through series of object Robot->enviroment->experiment->DataThread to second thread MainWindow->Dialog
in Gui Thread
QWaitCondition robotNextMoveWait;
QMutex robotNextMoveWaitMutex;
...
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(CSc anResults *)),SLOT(onRobotBeforeMove(CScanResults *)));
Q_ASSERT_X(bResult==true,"CDataThread::run","Connect 'm_stExperiment:robotBeforeMove ' with 'this:onRobotBeforeMove'");
//bResult = connect(m_ptrExperiment,SIGNAL(robotBeforeMove(CSc anResults *)),SIGNAL(robotBeforeMove(CScanResults *)));
//Q_ASSERT_X(bResult==true,"CDataThread::run","Connect 'm_stExperiment:robotBeforeMove ' with signal 'this:robotBeforeMove'");
exec();
}
Where did I make error? Could some one show me better solution? This is my second contact with threads.