Raspberry Pi + Pyqt: add_event_detect generates Py

2019-09-01 16:39发布

问题:

This is the code:

class MyWindowClass(QtGui.QMainWindow, form_class):
       def __init__(self, parent=None):

          GPIO.setmode(GPIO.BOARD) 
          GPIO.setup(26,GPIO.IN)

          QtGui.QMainWindow.__init__(self, parent)
          self.setupUi(self)

          self.alarm_detect()

       def alarm_detect(self):
          getattr(self, "AlarmePerifericos").setVisible(False)

          def alarme_perifericos(channel):
             if not (GPIO.input(channel)):
                 getattr(self, "AlarmePerifericos").setVisible(True)
             else: 
                 getattr(self, "AlarmePerifericos").setVisible(False)

          GPIO.add_event_detect(26, GPIO.BOTH, callback=alarme_perifericos)

app = QtGui.QApplication(sys.argv)
app.setStyle("GTK+") #Changing the style
myWindow = MyWindowClass(None)
myWindow.showFullScreen()
app.exec_()

I am running this PyQt script in a Raspberry Pi. When the program detects the pin 26, the QObject "AlarmePerifericos" is set to visible but I get the error QCoreApplication::sendPostedEvents: Cannot send posted events for objects in another thread. The thing is, as you can see, I am not in another thread. What is causing this? Can you help me?

Thank you.