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.
This commit is contained in:
tetektoza
2025-11-13 21:24:43 +01:00
parent 3f6a0ee78b
commit ca1528e2a9

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;
}