我试图写代码,其中采取输入从4x4键盘(机械)使用pad4pi模块与基于pyqt5的GUI应用程序。你知道吗
当我尝试单击按钮时,它工作正常,但当我尝试生成某个事件时,会收到错误消息:
QObject::startTimer: Timers can only be used with threads started with QThread
class DigitalClock(QWidget,QThread):
def __init__(self):
super().__init__()
SetupKeyboard.keypad.registerKeyPressHandler(self.printKey)
self.setWindowTitle("OM SAI RAM")
self.showFullScreen()
#self.setCursor(Qt.BlankCursor)
button = QPushButton("Click", self)
button.clicked.connect(self.change)
button.move(10,10)
button.show()
def change(self):
self.newpage = Authentication_page()
self.close()
def printKey(self, key):
if key == 'A':
self.newpage = Authentication_page()
self.close()
class Authentication_page(QWidget):
"""
Class to validate authentication.
"""
def __init__(self):
super().__init__()
self.showFullScreen()
self.maindesign()
def maindesign(self):
"""Method to design main page"""
####Label###
self.admin_header = QLabel("Admin Panel", self)
self.admin_header.setStyleSheet("font-size:40px")
self.admin_header.move(130, 10)
self.admin_header.show()
当我点击按钮代码工作正常,但当我按下机械按钮,代码冻结与错误信息。你知道吗
registerKeyPressHandler分配的处理程序在监视键的线程中执行,在您的情况下,printKey在试图创建小部件但Qt禁止的辅助线程中执行。你知道吗
解决方案是创建一个QObject并通过发送按下的键发出一个信号(因为信号是线程安全的),然后连接到接收信息的插槽:
相关问题 更多 >
编程相关推荐