问题描述
使用Qt串行GUI读取多个串行条形码扫描仪时,冻结了Q Line Edit 使用Spider可以正常运行,但是在python安装程序打包转换后运行时 扫描3或4个条形码后GUI冻结 请帮助清除此问题 下面给出的最小代码样本,实际上我使用4个串行端口进行读取
如何在不冻结GUI的情况下扫描条形码扫描器
from PyQt5.QtWidgets import QApplication,QVBoxLayout,QWidget
from PyQt5.QtWidgets import QMainWindow,QLabel
from PyQt5.QtCore import Qt,qiodevice
from PyQt5.QtSerialPort import QSerialPort
import sys
class ExampleGUI(QMainWindow):
def __init__(self):
super().__init__()
self.setwindowTitle("Example")
# Start mainLayout
self.mainLayout = QVBoxLayout()
serialLabel1 = QLineEdit("barcode_1")
self.mainLayout.addWidget(serialLabel1)
serialLabel2 = QLineEdit("barcode_2")
self.mainLayout.addWidget(serialLabel2)
widget = QWidget()
widget.setLayout(self.mainLayout)
self.setCentralWidget(widget)
self.ser1 = QtSerialPort.QSerialPort("COM1",baudrate=QtSerialPort.QSerialPort.Baud9600)
self.ser2 = QtSerialPort.QSerialPort("COM2",baudrate=QtSerialPort.QSerialPort.Baud9600)
self.ser1.open(qiodevice.ReadWrite)
self.ser2.open(qiodevice.ReadWrite)
self.ser1.readyRead.connect(self.bar_read1)
self.ser2.readyRead.connect(self.bar_read2)
def bar_read1(self):
self.ser1.waitForReadyRead(50)
barcode1 = self.ser1.readLine(14)
if len(barcode1)==5 :
barcode = (str(barcode1)[6:9])
self.barcode_1.setText(barcode)
def bar_read2(self):
self.ser2.waitForReadyRead(50)
barcode2 = self.ser2.readLine(14)
if len(barcode2)==5 :
barcode = (str(barcode2)[6:9])
self.barcode_2.setText(barcode)
if __name__ == '__main__':
app = QApplication([])
gui = ExampleGUI()
gui.show()
app.exec_()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)