我想監視連接到Beaglebone的自定義設備中的緊急停止按鈕,我的代碼是使用Qt 4.6開發的。Qt退出事件循環
目前,當按下緊急停止按鈕時,我成功地顯示了一個消息框(沒有任何按鈕)。我想要做的是繼續執行程序ONLY當緊急停止按鈕被釋放時。按鈕按下/釋放在每個事件上發出不同的信號。但是,使用此代碼時,EmergencyStopIsInactive信號從未被檢測到。
QEventLoop loop;
connect(this, SIGNAL(EmergencyStopIsInactive()), &loop, SLOT(quit()));
loop.exec(QEventLoop::AllEvents);
qDebug() << "Emergency Stop Deactivated";
事實上,使用斷點我可以看到它永遠不會生成。 Eventloop似乎沒有收到信號。
如果我註釋掉loop.exec行,使用斷點,我可以看到代碼發出信號。隨着執行命令回來,我們永遠不會到達斷點。
exec()似乎不允許應用程序處理事件。
我可以按照我想要的方式獲得此功能嗎?怎麼樣?
問候, 詹姆斯
====================================== = 編輯: 這是產生初始信號的代碼:
// Set up Emergency Stop Input
EmStop = new mita_gpio;
EmStop->initgpio_read(49);
connect(EmStop,SIGNAL(StateOutput(unsigned int)), this, SLOT(update_EmStop(unsigned int)));
connect(EmStop,SIGNAL(StateOutput(unsigned int)), Test_Screen, SLOT(update_EmStop(unsigned int)));
connect(this,SIGNAL(EmergencyStopIsInactive()), Probe_Screen, SLOT(quit()));
connect(Probe_Screen,SIGNAL(ShowEmergencyStopScreen()),this,SLOT(EmergencyStopScreenShow()));
此信號然後鏈接到以下內容:
void Manager::update_EmStop(unsigned int state_value)
{
if (state_value == 1)
{
MitaData.EmergencyStop = 1;
emit EmergencyStopIsActive();
qDebug() << "Emergency Stop = 1";
}
else
{
MitaData.EmergencyStop = 0;
emit EmergencyStopIsInactive();
qDebug() << "Emergency Stop = 0";
}
}
從哪裏發出?同一個線程?事件循環可能會阻止排放? –
發佈發出信號的代碼。 – sashoalm
您沒有更改'state_value'變量!它會一直進入同一個分支。 –