Details
Description
Hi.
QPlainTextEdit.setPlainText raises ValueError if the input Unicode string contains non-terminator NULL characters. Although C definition of a string is a sequence of characters terminated by a NULL byte, this is Python and a pythonic string could contain any characters (including NULL character).
QPlainTextEdit().setPlainText("A\x00B")
Stack-trace:
Traceback (most recent call last):
File "/tmp/reproduce.py", line 28, in <module>
window = Window()
File "/tmp/reproduce.py", line 20, in _init_
self.txtbox.setPlainText("A\x00B") # A(0x41), NUL(0x00), B(0x42)
ValueError: embedded null character
It's notable that copy-pasting a string containing NULL characters to a QPlainTextEdit works properly and there is no problem on PySide6 (PySide2 was buggy). QPlainTextEdit.toPlainText() returns the pasted text containing NULL bytes properly without truncation or raising an exception.
Interestingly, as I observed, QPlainTextEdit.setPlainText() works properly on PyQT5 and PyQT6 and does not raise an exception or truncate the string up the first NULL character.
Please check out the attached Python script to reproduce the issue.
Attachments
Issue Links
- relates to
-
PYSIDE-1895 QPlainTextEdit.setPlainText() truncates the passed Unicode string up to the first embedded NULL character
- Closed