Raspberry Pi + Pyqt:add_event_detect生成PyQt错误。为什么?

时间:2016-05-23 15:00:57

标签: python pyqt raspberry-pi gpio

这是代码:

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_()

我在Raspberry Pi中运行这个PyQt脚本。当程序检测到引脚26时,QObject" AlarmePerifericos"设置为可见,但我收到错误QCoreApplication::sendPostedEvents: Cannot send posted events for objects in another thread。事情是,正如你所看到的,我不在另一个线程中。是什么造成的?你能救我吗?

谢谢。

0 个答案:

没有答案