[PyQt] QString mutable, unicode string immutable
Wolfgang Rohdewald
wolfgang at rohdewald.de
Thu Feb 26 21:58:35 GMT 2009
Hi,
I just found out the hard way what the subject says
Now I am curious: The PyQt roadmap says that non-pythonic classes
like QString will be removed. So the result of some Qt/KDE methods
will no longer return a mutable result but an immutable result.
Could this not break code that relies on the result being mutable?
This is the concrete case I had:
In a class derived from kdeui.KConfigSkeleton:
(this code is edited to a minimum, might not run)
self._value = QString()
self.configValue = self.addItemString('value',self._value,QString('default'))
after the config dialog I save the new value elsewhere:
saveValue = config.configValue.value()
now saveValue is a QString
after next config dialog I check if the value changed:
if saveValue != config.configValue.value():
self.applyChanges()
but since theye are QStrings, they are always identical -
the config dialog also changes my saveValue.
of course the solution is simple: saveValue = str(config.configValue.value())
--
Wolfgang
More information about the PyQt
mailing list