Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Emoji on button labels causes a silent crash
Forum Updated to NodeBB v4.3 + New Features

Emoji on button labels causes a silent crash

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
6 Posts 3 Posters 449 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Joel Santos
    wrote last edited by
    #1

    Hi,

    I'm new to Qt, and I'm using Qt Creator to lay out my GUI. I wanted to get some emoji in my button labels to break the monotony of a very text-heavy app, but when I do, the app silently crashes. I managed to track the point were it fails and replicate it with a minimum app that shows the issue (I attach the ui file below, that should be enough to generate the issue). I'm using PySide6 (6.9.2), Python 3.13 on Windows 11.

    The issue is in the autogenerated code from .ui to .py. On it, retranslateUI() is called on the widgets that have text on it, which in turn calls setText() with QCoreApplication.translate() and a escaped sequence for the emoji, which triggers the crash.

    In the minimal app I attach, my main widget is EmojiButton, defined in emojibutton.py

    # in emojybutton.py
    class EmojiButton(QWidget):
        def __init__(self, parent=None):
            super().__init__(parent)
            self.ui = Ui_EmojiButton()
            self.ui.setupUi(self)
    

    Ui_EmojiButton is autogenerated from the ui file:

    # in autogenerated ui_form.py
    class Ui_EmojiButton(object):
        def setupUi(self, EmojiButton):
            [...]
            self.retranslateUi(EmojiButton)
            [...]
        def retranslateUi(self, EmojiButton):
            EmojiButton.setWindowTitle(QCoreApplication.translate("EmojiButton", u"EmojiButton", None))
            self.pushButton.setText(QCoreApplication.translate("EmojiButton", u"Click me \ud83d\ude80", None))
    

    If I change the autogenerated code from a escaped sequence to a literal emoji, the app works

    # changing
    self.pushButton.setText(QCoreApplication.translate("EmojiButton", u"Click me \ud83d\ude80", None)) # doesn't work 
    # for
    self.pushButton.setText(QCoreApplication.translate("EmojiButton", u"Click me ๐Ÿš€", None)) # works!
    

    But because it's autogenerated code, next time I generate it, it will revert back.

    I've noticed a "translatable" property that I can uncheck, which also fixes the issue, as QCoreApplication.translate() is not called with an escaped sequence. I asked in stack overflow and people pointed out that this would also work, while still maintaining a "escape sequence" style, but again, can't change it as it's part of the autogenerated code

    self.pushButton.setText(QCoreApplication.translate("EmojiButton", u"Click me \U0001f680", None)) # this scape sequence works too
    

    For now, the solution seems to be to uncheck the "translatable" property, which is good for me, but it seems like a bug to me, and I wasn't capable of finding anything related to it in the forum.

    PS: while writing this post, I just noticed that the "escape sequence" of ๐Ÿš€ is \U0001f680, which doesn't seem to have any relation to the \ud83d\ude80 generated by pyside6-uic, so maybe the error is there?
    If I change the autogenerated

    # changing
    self.pushButton.setText(QCoreApplication.translate("EmojiButton", u"Click me \ud83d\ude80", None)) # doesn't work 
    # for
    self.pushButton.setText(QCoreApplication.translate("EmojiButton", u"Click me \u0001\uf680", None)) # no emoji on the button (shows two squares) but at least runs
    

    Here's the ui file that generates the issue and should be enough to replicate it

    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
     <class>EmojiButton</class>
     <widget class="QWidget" name="EmojiButton">
      <property name="geometry">
       <rect>
        <x>0</x>
        <y>0</y>
        <width>287</width>
        <height>198</height>
       </rect>
      </property>
      <property name="windowTitle">
       <string>EmojiButton</string>
      </property>
      <widget class="QPushButton" name="pushButton">
       <property name="geometry">
        <rect>
         <x>80</x>
         <y>80</y>
         <width>111</width>
         <height>31</height>
        </rect>
       </property>
       <property name="font">
        <font>
         <pointsize>16</pointsize>
        </font>
       </property>
       <property name="text">
        <string>Click me ๐Ÿš€</string>
       </property>
      </widget>
     </widget>
     <resources/>
     <connections/>
    </ui>
    
    S 1 Reply Last reply
    0
    • J Joel Santos

      Hi,

      I'm new to Qt, and I'm using Qt Creator to lay out my GUI. I wanted to get some emoji in my button labels to break the monotony of a very text-heavy app, but when I do, the app silently crashes. I managed to track the point were it fails and replicate it with a minimum app that shows the issue (I attach the ui file below, that should be enough to generate the issue). I'm using PySide6 (6.9.2), Python 3.13 on Windows 11.

      The issue is in the autogenerated code from .ui to .py. On it, retranslateUI() is called on the widgets that have text on it, which in turn calls setText() with QCoreApplication.translate() and a escaped sequence for the emoji, which triggers the crash.

      In the minimal app I attach, my main widget is EmojiButton, defined in emojibutton.py

      # in emojybutton.py
      class EmojiButton(QWidget):
          def __init__(self, parent=None):
              super().__init__(parent)
              self.ui = Ui_EmojiButton()
              self.ui.setupUi(self)
      

      Ui_EmojiButton is autogenerated from the ui file:

      # in autogenerated ui_form.py
      class Ui_EmojiButton(object):
          def setupUi(self, EmojiButton):
              [...]
              self.retranslateUi(EmojiButton)
              [...]
          def retranslateUi(self, EmojiButton):
              EmojiButton.setWindowTitle(QCoreApplication.translate("EmojiButton", u"EmojiButton", None))
              self.pushButton.setText(QCoreApplication.translate("EmojiButton", u"Click me \ud83d\ude80", None))
      

      If I change the autogenerated code from a escaped sequence to a literal emoji, the app works

      # changing
      self.pushButton.setText(QCoreApplication.translate("EmojiButton", u"Click me \ud83d\ude80", None)) # doesn't work 
      # for
      self.pushButton.setText(QCoreApplication.translate("EmojiButton", u"Click me ๐Ÿš€", None)) # works!
      

      But because it's autogenerated code, next time I generate it, it will revert back.

      I've noticed a "translatable" property that I can uncheck, which also fixes the issue, as QCoreApplication.translate() is not called with an escaped sequence. I asked in stack overflow and people pointed out that this would also work, while still maintaining a "escape sequence" style, but again, can't change it as it's part of the autogenerated code

      self.pushButton.setText(QCoreApplication.translate("EmojiButton", u"Click me \U0001f680", None)) # this scape sequence works too
      

      For now, the solution seems to be to uncheck the "translatable" property, which is good for me, but it seems like a bug to me, and I wasn't capable of finding anything related to it in the forum.

      PS: while writing this post, I just noticed that the "escape sequence" of ๐Ÿš€ is \U0001f680, which doesn't seem to have any relation to the \ud83d\ude80 generated by pyside6-uic, so maybe the error is there?
      If I change the autogenerated

      # changing
      self.pushButton.setText(QCoreApplication.translate("EmojiButton", u"Click me \ud83d\ude80", None)) # doesn't work 
      # for
      self.pushButton.setText(QCoreApplication.translate("EmojiButton", u"Click me \u0001\uf680", None)) # no emoji on the button (shows two squares) but at least runs
      

      Here's the ui file that generates the issue and should be enough to replicate it

      <?xml version="1.0" encoding="UTF-8"?>
      <ui version="4.0">
       <class>EmojiButton</class>
       <widget class="QWidget" name="EmojiButton">
        <property name="geometry">
         <rect>
          <x>0</x>
          <y>0</y>
          <width>287</width>
          <height>198</height>
         </rect>
        </property>
        <property name="windowTitle">
         <string>EmojiButton</string>
        </property>
        <widget class="QPushButton" name="pushButton">
         <property name="geometry">
          <rect>
           <x>80</x>
           <y>80</y>
           <width>111</width>
           <height>31</height>
          </rect>
         </property>
         <property name="font">
          <font>
           <pointsize>16</pointsize>
          </font>
         </property>
         <property name="text">
          <string>Click me ๐Ÿš€</string>
         </property>
        </widget>
       </widget>
       <resources/>
       <connections/>
      </ui>
      
      S Offline
      S Offline
      SimonSchroeder
      wrote last edited by
      #2

      @Joel-Santos said in Emoji on button labels causes a silent crash:

      PS: while writing this post, I just noticed that the "escape sequence" of ๐Ÿš€ is \U0001f680, which doesn't seem to have any relation to the \ud83d\ude80 generated by pyside6-uic, so maybe the error is there?

      In UTF-16 (which Qt uses internally), Unicode code points starting from \U00010000 don't fit into 16 bits anymore. This is why your emoji needs a so-called surrogate pair in UTF-16. You cannot easily see how the surrogate pair relates to the original code point. But, \ud83d\ude80 is the Unicode character encoded as UTF-16. Qt decided to use 16 bits when Unicode didn't have that many characters (back then it was called UCS-2; Windows has the same problem). Maybe this is from back in the day when 16 bits were enough.

      This is certainly a bug. However, this is a user forum and you'll not reach developers through this. You should file an official bugreport instead (https://bugreports.qt.io).

      @Joel-Santos said in Emoji on button labels causes a silent crash:

      I asked in stack overflow and people pointed out that this would also work, while still maintaining a "escape sequence" style, but again, can't change it as it's part of the autogenerated code

      Can you write \U0001f680 inside the .ui-file directly? It might not show up in the Qt Designer correctly or might even be destroyed when saving from the Designer again.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Joel Santos
        wrote last edited by Joel Santos
        #3

        @SimonSchroeder thanks for your reply. I filled a bug. I wanted to ask the opinion of more expert users before doing it.

        Regarding your suggestion, I tried, but then it prints the string \U0001f680, so the parser in pyside6-uic doesn't allow to work around it.

        I'll close this as it seems to be a bug, any poor soul that encounters this and is not tranlsating their app, they can deselect the translatable check in the QAbstractMethod properties.

        Thanks!

        SGaistS 1 Reply Last reply
        0
        • J Joel Santos has marked this topic as solved
        • J Joel Santos

          @SimonSchroeder thanks for your reply. I filled a bug. I wanted to ask the opinion of more expert users before doing it.

          Regarding your suggestion, I tried, but then it prints the string \U0001f680, so the parser in pyside6-uic doesn't allow to work around it.

          I'll close this as it seems to be a bug, any poor soul that encounters this and is not tranlsating their app, they can deselect the translatable check in the QAbstractMethod properties.

          Thanks!

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote last edited by
          #4

          @Joel-Santos hi,

          Did you open a ticket about this ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          S 1 Reply Last reply
          0
          • SGaistS SGaist

            @Joel-Santos hi,

            Did you open a ticket about this ?

            S Offline
            S Offline
            SimonSchroeder
            wrote last edited by
            #5

            @SGaist https://bugreports.qt.io/browse/PYSIDE-3173

            1 Reply Last reply
            1
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote last edited by
              #6

              Thank you !

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved