Найти - Пользователи
Полная версия: Кодировка из Qt.LineEdit
Начало » GUI » Кодировка из Qt.LineEdit
1
Fenec
Пишу прогу на питоне+qt

открываю файл: file = codecs.open('data.txt', ‘r’, ‘utf-8’).readlines() - кодировка utf-8
self.edit = QtGui.QLineEdit(self)
str(self.edit.text()) - читаю в строку значение из инпута

ошибка: UnicodeEncodeError: ‘ascii’ codec can't encode characters in position 0-3: ordinal not in range(128)

как сделать, чтобы значение из инпута было в utf-8, а не ascii?
bazooka
использовать unicode вместо str

еще можно использовать sip.setapi('QString', 2) и тогда там где возвращялся QString будет возвращятся уникод
http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/pyqt4ref.html#qstring
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB