0
I created an application where the user presses a certain key combination - using the package pynput
- and a message from a "Qtoaster" appears on screen. Below is an example code:
from pynput import keyboard
from toaster import show_message # Toaster criado a partir de um QFrame com QTimer
from PyQt5.QtWidgets import QApplication
def func():
show_message("Executado com sucesso.")
app = QApplication([])
thread = keyboard.GlobalHotKeys({"<ctrl>+<alt>+z": func})
thread.start()
app.exec_()
The problem is that whenever I run the code and press the keys, the QToaster
crashes and the following error message is printed on the console:
QObject::startTimer: Timers can only be used with threads started with QThread
I know this error is being generated because Qtoaster is not created on main thread. My question is: how to execute the QToaster
from another Thread without it locking, from a sign or something? In Pyqt5 there is some feature that allows me to execute a code of a different Thread from a signal, as in the code below?
executor = Executor()
executor.set_function(lambda: show_message("Executado com sucesso."))
thread = keyboard.GlobalHotKeys({"<ctrl>+<alt>+z": executor.start})
thread.start()