The QVariant
type doesn't exsits any more so any methods returning QVariant
will be auto converted to Python types. You no longer need to convert the return type using the toXXXX
methods.
Remove all:
toString()
toList()
toInt()
toStringList()
toByteArray()
QVariant(..)
QString(...)
Set QSettings return type
More info: http://pyqt.sourceforge.net/Docs/PyQt4/pyqt_qsettings.html
Before:
settings.value(“/yourboolsetting”, True).toBool()
settings.value(“/yourintsetting”, 10).toInt()[0]
settings.value(“/yourintsetting”).toByteArray()
After:
settings.value(“/yourboolsetting”, True, type=bool)
settings.value(“/yourintsetting”, 10, type=int)
settings.value(“/yourintsetting”, QByteArray(), type=QByteArray)
Replace QString methods
QString
no longer exits in the new QGIS API. Any methods that return a QString
will be converted into a native Python str
. All QString methods need to be replaced with native string methods.
Before:
yourstring.right(4)
files.join(",")
if yourstring.length() > 4:
if yourstring.isEmpty()
After:
yourstring[4:]
",".join(files)
if len(yourstring) > 4
if not yourstring
Replace QStringList with list
Before:
mystrings = QStringList()
After:
mystrings = []
Remove QVariant calls
The QVariant
also doesn't exsits any more so any methods returning QVariant
will be auto converted to Python types. However QVariant
can still be used to access it's emun values e.g. QVariant.Int
can set be used.
Before:
myvalue = QVariant(10)
myvalue = QVariant("Hello World")
After:
myvalue = 10
myvalue = "Hello World"
Replace signals with new style signals and connections
Before:
self.emit(SIGNAL("valuesChanged(const QStringList &)"), self.getArguments())
After:
class Test():
valuesChagned = QtCore.pyqtSignal(list)
def yourmethod():
self.valuesChagned.emit(self.getArguments)
@NathanW2: isn't it opposite? In Python 2.x QString is directly mapped to unicode. In 3.0 I guess it's not necessary so it stays in the "plain" str.