Python Pyqt5: Why string storage in QLineedit is different to standard python input()?

34 views Asked by At

I want to read strings from a USB tag reader, this strings contains ascii chars. When use input() works good:

string=input("read: ")
read: 0100630414610870103BD0291724060124011537241422840
string
'0100630414610870103BD029\x1d1724060124011537241\x1d422840'
'\x1d' in string
True

If I use pyqt5 QLineEdit the special chars disappear:

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QVBoxLayout
class MiVentana(QWidget):
    def __init__(self):
        super().__init__()
        self.init_ui()
    def init_ui(self):
        self.line_edit = QLineEdit(self)
        self.etiqueta = QLabel('Texto ingresado:', self)
        layout = QVBoxLayout()
        layout.addWidget(self.line_edit)
        layout.addWidget(self.etiqueta)
        self.setLayout(layout)
        self.line_edit.returnPressed.connect(self.actualizar_etiqueta)
        self.setWindowTitle('Ejemplo de QLineEdit')
        self.setGeometry(300, 300, 300, 150)

    def actualizar_etiqueta(self):
        texto_ingresado = self.line_edit.text()
        self.etiqueta.setText('Texto ingresado: ' + texto_ingresado)
        texto_ingresado
        if '\xd1' not in texto_ingresado:
            print("missing chars")
        print(texto_ingresado)
        

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ventana = MiVentana()
    ventana.show()
    sys.exit(app.exec_())

output:
missing chars
0100630414610870103BD0291724060124011537241422840

Python version is 3.11, PyQt5-5.15, why QLineEdit remove the specials chars? who can I read all chars?

I try it in anothers PCs with the same result.

0

There are 0 answers