[PyQt] PyQt Digest, Vol 137, Issue 5

David Cortesi davecortesi at gmail.com
Fri Dec 4 16:49:31 GMT 2015


From: Kerri Reno <kreno at yumaed.org>

>
> Got a response to this on stackoverflow - thanks!
>
> http://stackoverflow.com/questions/34055174/qvalidator-fixup-issue
>

This is interesting. Your problem resulted from a subtle effect of the
change from using native QStrings in PyQt4, to hiding the QString class and
using only Python str and bytes types in PyQt5. In PyQt4, apparently the
expression

    text += '-'

given text a QString, invoked QString.append(), modifying the object that
was passed as the function argument.

In PyQt5, the QString passed by Qt is automatically coerced to a Python str
type. By Python rules, the argument "text" is just another local variable.
The expression assigned a new value to the name "text" within the function,
but that has no effect on the string passed (other than to reduce its
reference count).

However I am dubious about the SO answer's suggestion to use

    text.append('-')

because neither the str or bytes types have that method! Did this
actually work for you in Python3/PyQt5?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20151204/2422e8af/attachment.html>


More information about the PyQt mailing list