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. QBasicTimer can be used with threads started with QThread,when widget.setFocus()
QtWS25 Last Chance

QBasicTimer can be used with threads started with QThread,when widget.setFocus()

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 2 Posters 924 Views
  • 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.
  • S Offline
    S Offline
    sLawalata
    wrote on last edited by sLawalata
    #1

    I always get this error message.

    QBasicTimer can be used with threads started with QThread,when widget.setFocus()
    

    Basically, I have a class Rotary which is listening to GPIO.
    it has myForm.dial_on_value_changed() registered as a callback to Rotary which will call dial_on_value_changed() when rotator is rotated.

    If myForm.dial_on_value_changed() only prints a text or string then it is fine. But if it selected one of myForm element and change its state such as setFocus(True), it will throw the above error, smth related with QThread.

    My Application is a single thread and Rotari itself works based on listening to an interrupt in a GPIO pin which will call registered callback function.

    can someone tell me or guide me what I have done wrong? Or maybe a better way to solve this problem which is "A knob which will rotate and set all GUI element to be focused"

    thanks in advance.

    This is my snipset code

     class MyForm(QDialog):
       # createing a circular list
       self._vt_dial_cycle = cycle([
            # tuple UI element with a function
            (self.vt_textedit, self.dial_to_vt),
            (self.rr_textedit, self.dial_to_rr),
            (self.stop_button, None),
            (self.start_button, None),
            (self.ie_textedit, self.dial_to_ie)
       ])
    
    
    def dial_to_vt(self):
        print("Dial on vt")
    
    def dial_to_rr(self):
        print("Dial on rr")
    
    def dial_to_ie(self):
        print("Dial on ie")
    
    def dial_on_value_changed(self, direction):
    	# get next element from circular list.
        (active_widget, action) = next(self._vt_dial_cycle)
        self._current_widget = (active_widget, action)
    
        #execute action manually registered with widget
        action()
    
        if isinstance(active_widget, QTextEdit):
            self.move_cursor_to_end(active_widget)
    
    if __name__ == "__main__":
        app = QApplication(sys.argv)
        w = MyForm()
        w.show()
    
        # ... a rotari with a knop 
        ky040 = KY040(CLOCKPIN, DATAPIN, SWITCHPIN, w.dial_on_value_changed, w.dial_on_pressed)
        
        ky040.start()
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You are accessing a GUI element from a different thread than the GUI thread which is forbidden. Your GPIO controller class should rather emit signals based on whatever it is you do with it and you should connect these signals on the appropriate slots in your GUI.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1

      • Login

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