1

I am using PyQt and want to get string from text field. I found below solution but it returns a QString. I just want to avoid writing extra code to extract string further. Can anyone suggest a simple solution to retrieve text from text field.

text = self.your_plugin_dlg.ui.yourLineEdit.text()

Thanks.

qurat
  • 439
  • 1
  • 7
  • 14

1 Answers1

0

The only way to get the text is converting the QString into a String

text = str(self.your_plugin_dlg.ui.yourLineEdit.text())
Oisin
  • 770
  • 8
  • 22
  • Well Thanks. But can you explain that what .text() returns in actual? and how str() solved the issue? – qurat Feb 07 '16 at 13:34
  • It is a bug to convert `QString` using `str()` in Python 2. If the text contains non-ascii characters, it will raise a `UnicodeDecodeError`. – ekhumoro Feb 07 '16 at 18:00