Gui: Use UTF-8 string instead of UTF-16 for Reset in Expression Editor

Currently `ExpLineEdit::apply()` passes `QString::constData()` to a
printf-style format string with %s. `QString::constData() returns a
const QChar* (UTF-16, 2 bytes per char), but %s expects a const char*
(UTF-8/ASCII with 1 byte per char).

This results in a string being interpreted as in "Container":
Byte 0: 'C'
Byte 1: 0x00 (high byte of UTF-16 'C', which gets interpreted as null
terminator)

So this patch uses proper conversion to null-terminated C-String before
passing it further.

(cherry picked from commit ca1528e2a9)
This commit is contained in:
tetektoza
2025-11-18 17:51:51 +01:00
committed by Max Wilfinger
parent 3c6cdb17e0
commit 08cceec9cf
+6 -1
View File
@@ -1577,7 +1577,12 @@ bool ExpLineEdit::apply(const std::string& propName)
if (!ExpressionBinding::apply(propName)) {
if (!autoClose) {
QString val = QString::fromUtf8(Base::Interpreter().strToPython(text().toUtf8()).c_str());
Gui::Command::doCommand(Gui::Command::Doc, "%s = \"%s\"", propName.c_str(), val.constData());
Gui::Command::doCommand(
Gui::Command::Doc,
"%s = \"%s\"",
propName.c_str(),
val.toUtf8().constData()
);
}
return true;
}