Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Software triggered event
Forum Updated to NodeBB v4.3 + New Features

Software triggered event

Scheduled Pinned Locked Moved Solved Qt for Python
6 Posts 3 Posters 1.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dtruex
    wrote on last edited by
    #1

    I am running PyQt5 on a Raspberry PI 3B+. There are some add on boards that trigger an interrupt in response to some external events. Presently the interrupt service routine needs to read some information from the external hardware to determine the cause of the interrupt but this causes problems if the interrupt occurs when the code is in the process of reading or writing to the hardware. I would like to change the ISR to simple trigger and event with a callback that is handled by the main task handler, in other words an event that can be manually triggered in software. How do I do this in PyQt?

    # the ISR would look like this
    def externalINT(self):
         triggerMyEvent()
    
    #the event handler would be called by the main event handler
    def myEventHandler(self):
         readIntCause()  
         #etc
    

    Thanks.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      Do you mean like a custom event ?

      Your handler must be in a QObject class.

      sorry Im a python noob so cant type it.

      hopefully the c++ version is clear enough

        const QEvent::Type MyEvent = (QEvent::Type)1234;
          ...
          QApplication::postEvent(obj, new QCustomEvent(MyEvent));
          
      The event must be of type QCustomEvent (or a subclass). The argument to the constructor is the type of event. Values under 1024 are reserved by Qt for predefined event types; other values can be used by applications.
      
      To handle custom event types, reimplement the customEvent() function:
      
          void yourwidget::customEvent(QCustomEvent *event)
          {
              if (event->type() == MyEvent) {
                 // do it!
              } else {
                  baseeclass::customEvent(event);
              }
          }
          
      
      1 Reply Last reply
      4
      • D Offline
        D Offline
        dtruex
        wrote on last edited by
        #3

        That sounds like exactly what i need but I am also a Python noob so not sure how to pull it off.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dtruex
          wrote on last edited by
          #4

          Searching for "custom event" resulted in finding this: http://zetcode.com/gui/pyqt5/eventssignals/

          The example entitled "Emitting Signals" looks promising. I'll post an update after I give it a try but would appreciate any additional suggestions.

          Thanks

          mrjjM D 2 Replies Last reply
          1
          • D dtruex

            Searching for "custom event" resulted in finding this: http://zetcode.com/gui/pyqt5/eventssignals/

            The example entitled "Emitting Signals" looks promising. I'll post an update after I give it a try but would appreciate any additional suggestions.

            Thanks

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @dtruex
            Well the normal event functions are very much
            like the customEvent so you would overwrite it in same manner.

            like

            
            class Example(QWidget):
                    
                def customEvent(self, e):
                 ...
            

            (i would assume )

            Anyway, the signal section seems to be a normal Qt signals which is not like an event in Qt as such.
            But signals and slots could also be used.

            Did you read
            https://doc.qt.io/qtforpython/overviews/signalsandslots.html
            Im aware you are using PyQt but the overall design etc is the same.

            1 Reply Last reply
            0
            • D dtruex

              Searching for "custom event" resulted in finding this: http://zetcode.com/gui/pyqt5/eventssignals/

              The example entitled "Emitting Signals" looks promising. I'll post an update after I give it a try but would appreciate any additional suggestions.

              Thanks

              D Offline
              D Offline
              dtruex
              wrote on last edited by
              #6

              @dtruex

              @dtruex said in Software triggered event:

              Searching for "custom event" resulted in finding this: http://zetcode.com/gui/pyqt5/eventssignals/

              The example entitled "Emitting Signals" looks promising. I'll post an update after I give it a try but would appreciate any additional suggestions.

              Thanks

              The approach suggested in the article in the link above solved the problem.

              class Communicate(QObject):
                  intSig = pyqtSignal() 
              
              class MainWindow(QMainWindow):    
                  self.c = Communicate()
                  self.c.intSig.connect(self.piPlateINT2)
              etc
              
              #ISR
              def piPlateINT(self,channel):
                      self.c.intSig.emit()
              
              #the code 
              def piPlateINT2(self):
                      self.buttonIntCount = self.buttonIntCount + 1
              etc
              
              1 Reply Last reply
              2

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved