Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-1895

QPlainTextEdit.setPlainText() truncates the passed Unicode string up to the first embedded NULL character



    • Bug
    • Resolution: Done
    • P4: Low
    • None
    • 6.3.0
    • PySide
    • None
    • Python 3.9 - Ubuntu 20.04
    • Linux/X11
    • f2b4abb43e (pyside/pyside-setup/dev) 5fea947741 (pyside/pyside-setup/6.3) 5fea947741 (pyside/tqtc-pyside-setup/6.3) f2b4abb43e (pyside/tqtc-pyside-setup/dev)


      According to the Qt6 documentation, embedded NULL characters are allowed in a QString:

      "A QString can embed '\0' characters (QChar::Null). The size() function always returns the size of the whole string, including embedded '\0' characters."

      Also, Unicode strings in Python can contain NULL characters. So obviously nothing prevents the under-layer QString and the Pythonic equivalent str instance from containing NULL characters and it's OK to have them in a string as they are valid characters.

      To ensure the under-layer Qt interface handles embedded NULL characters in a string properly when working with a QPlainTextEdit (or a QTextEdit) I coded a simple program in C++ that indicates it works properly. Please check the attached C++ file "main.cpp" to reproduce.

      However, the PySide6 equivalent of the program fails! It truncates the string passed to QPlainTextEdit.setPlainText() up to the first NULL character in the string resulting in data integrity loss. Please check the attached Python file "main.py" to reproduce.

      PyUnicode_PythonToCpp_QString len= 3 _PepUnicode_KIND= 1
      PyUnicode_PythonToCpp_QString lat= "A"


        1. main.cpp
          2 kB
          Bulmaro Jerrick
        2. main.py
          2 kB
          Bulmaro Jerrick
        3. pyside1882_diag.diff
          1 kB
          Friedemann Kleint

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.



              kleint Friedemann Kleint
              bulmaro.jerrick Bulmaro Jerrick
              0 Vote for this issue
              1 Start watching this issue



                Gerrit Reviews

                  There are no open Gerrit changes