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