To convert one QString in Python 2, do this:
self.name = unicode(self.new_label.text())
To automatically convert all QStrings, put this at the beginning of your code:
import sip
sip.setapi('QString', 2)
# must be before any pyqt imports
from PyQt4 import QtCore, QtGui
If you do this, there's no need to keep using unicode()
, because all methods will return python strings instead of QStrings. And note that with Python 3, this behaviour is the default, so you would not need to do anything to always get python strings.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…