[PyQt] Qstring and encode

Phil phil_lor at bigpond.com
Mon Sep 25 02:43:29 BST 2017


Thank you for reading this.

I retrieve text from a lineEdit like this:

mytext =  self.lineEdit.text()

However, I need to convert the string to a byte array for pyserial.

I can use a python string (but not a QString)like this:

mytext = mytext + "\n"
mybytes = mytext.encode('ascii') # or I can use 'utf-8') 
ser.write(mybytes)

QString doesn't have an encode attribute. How can I overcome this?

I had used bytes(mytext) which worked from within Eric but not from the 
command prompt. Apparently, bytes is not part of python3.

-- 
Regards,
Phil


More information about the PyQt mailing list