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

Emojis on Button Label Silently Crash PySide App

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3: Somewhat important P3: Somewhat important
    • 6.9.3, 6.10.1, 6.11.0
    • 6.10.0
    • PySide
    • None
    • Qt Creator v17.0
      PySide6 6.9.1
      Windows 11
    • Windows
    • adeed73aa (dev), 139dd9da7 (6.9), c4ee8bccf (tqtc/lts-6.8), 992e4d89e (dev), a50f38b63 (dev), 2facf3fb9 (6.10), 77ae4e2fd (6.10), dee11ba23 (6.9), 7544e7077 (6.9)

      When I add an emoji to a button label, the app silently crashes when I run it.

       

      I use Qt Creator v17.0 to create the layout of my app. I'm working on Python, using PySide6 (v6.9.1 on Python 3.13.2) and run it on Windows 11. I translate my .ui file into python code with pyside6-uic.

       

      I debugged my app and tracked the cause of the issue to the retranslateUI() method (in the autogenerated part of the code). On it, the label of the button is set with

      self.pushButton.setText(QCoreApplication.translate("EmojiButton", u"Click me \ud83d\ude80", None))

      I think the error comes from QCoreApplication.translate(), as it seems it can't handle the escaped sequences that Qt Creator generates.

      If I change the code into

      self.pushButton.setText(QCoreApplication.translate("EmojiButton", u"Click me 🚀", None)) 

      then the code works. Interestingly, if I use the 32bit escaped sequence of the emoji

      self.pushButton.setText(QCoreApplication.translate("EmojiButton", u"Click me \U0001f680", None))

      It works too! Sadly, that's not a viable solution, as this code is in the autogenerated part of the code and would be overwritten in the next change of the UI.

      In the meantime, I avoid the issue by marking the button as not translatable.

      I don't know if the bug is in PySide (as in, it should be able to parse the 16bit escape sequences) or in Qt Creator (it doesn't create the correct escape sequences). So feel free to move it if you think it's not in the correct section

      I attach a minimal app to replicate the issue

       UnicodeEncodeError: 'utf-8' codec can't encode characters in position 9-10: surrogates not allowed
      

      Python:

      u"Click me \ud83d\ude80"
      

      C++:

        "Click me \360\237\232\200"
      

       

        1. EmojiButton.zip
          4 kB
          Joel Santos Rico
        2. qtcreatorbug33435_stack.txt
          38 kB
          Friedemann Kleint
        3. pyside3173.zip
          2 kB
          Friedemann Kleint
        4. pyside3173_cpp.zip
          2 kB
          Friedemann Kleint
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            kleint Friedemann Kleint
            joelsantos Joel Santos Rico
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: