3
我有一个运行用Qt编写的GUI程序的Raspberry Pi 3。我使用wiringPi library来设置一个中断,当某个GPIO引脚变为低电平时触发。发生这种情况时,我想要一个对话窗口,告诉用户Pi将在10秒内关闭,在此期间他们可以选择取消关闭。如何在处理中断时返回主GUI线程?
问题是接收中断的函数在新线程中启动,而Qt不允许在主线程之外使用定时器等。我想知道如何从中断函数返回主线程。该函数不接受任何参数,顺便说一句。
示例代码:
MainWindow::MainWindow() {
wiringPiSetup();
//Set up an interrupt to detect when WiringPI pin 0 (header #11) goes low
//Call the ShutdownISR function when this happens.
wiringPiISR(0, INT_EDGE_FALLING, &ShutdownISR);
}
//Non-member, free function. Handles interrupt.
void ShutdownISR() {
//Crashes the program with errors about doing GUI stuff outside the main thread
ShutdownDialog* sdDlg = new ShutdownDialog();
sdDlg->exec();
}
Qt文档中的示例非常完美。谢谢。 – Carlton