How do I get back to the main GUI thread when handling an interrupt?

I have a Raspberry Pi 3 running a GUI program written in Qt. I am using the libraryPi library to set an interrupt that fires when a certain GPIO pin goes low. When this happens, I want a dialog box to appear informing the user that the Pi will close after 10 seconds, during which they have the option to cancel the shutdown.

The problem is that the function that receives the interrupt is run on a new thread, and Qt does not allow timers, etc. outside the main thread. I would like to know how I can get back to the main thread from the interrupt function. The function takes no arguments, btw.

Sample code:

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();
} 

      

+3


source to share


1 answer


AFAIU interrupts are handled only by the Linux kernel and do not appear directly in the application code. Be aware of unix signals , however, and read signal (7) and security alarms (7) and Advanced Programming on Linux and Operating Systems: Three Simple Pieces



As for Qt and signals, this is documented; see Calling Qt Functions from Unix Signal Handlers

+3


source







All Articles