Emoji on button labels causes a silent crash
-
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 callssetText()
withQCoreApplication.translate()
and a escaped sequence for the emoji, which triggers the crash.In the minimal app I attach, my main widget is
EmojiButton
, defined inemojibutton.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 theui
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 codeself.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 bypyside6-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>
-
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 callssetText()
withQCoreApplication.translate()
and a escaped sequence for the emoji, which triggers the crash.In the minimal app I attach, my main widget is
EmojiButton
, defined inemojibutton.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 theui
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 codeself.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 bypyside6-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>
@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. -
@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 theQAbstractMethod
properties.Thanks!
-
-
@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 theQAbstractMethod
properties.Thanks!
@Joel-Santos hi,
Did you open a ticket about this ?
-
@Joel-Santos hi,
Did you open a ticket about this ?
-
Thank you !