Skip to content

Commit 1aa735b

Browse files
lassoanjcfr
authored andcommitted
Fix passing of non-ASCII characters as command-line arguments
Should fix the issues described here: https://discourse.slicer.org/t/slicer-ignoring-command-line-path-with-accents/24569
1 parent 73924c8 commit 1aa735b

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

Base/Testing/Cpp/ctkAppLauncherEnvironmentTest.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,24 @@ void ctkAppLauncherEnvironmentTester::cleanup()
5252
QStringList originalEnvKeys = ctkAppLauncherEnvironment::envKeys(this->OriginalEnv);
5353
foreach(const QString& varName, originalEnvKeys)
5454
{
55-
qputenv(varName.toLatin1(), this->OriginalEnv.value(varName).toLatin1());
55+
qputenv(varName.toLocal8Bit(), this->OriginalEnv.value(varName).toLocal8Bit());
5656
}
5757
}
5858

5959
// ----------------------------------------------------------------------------
6060
void ctkAppLauncherEnvironmentTester::setEnv(const QString& name, const QString& value)
6161
{
62-
qputenv(name.toLatin1(), value.toLatin1());
62+
qputenv(name.toLocal8Bit(), value.toLocal8Bit());
6363
this->VariableNames.insert(name);
6464
}
6565

6666
// ----------------------------------------------------------------------------
6767
void ctkAppLauncherEnvironmentTester::unsetEnv(const QString& name)
6868
{
6969
#if defined(_MSC_VER)
70-
qputenv(name.toLatin1(), QString("").toLatin1());
70+
qputenv(name.toLocal8Bit(), QString().toLocal8Bit());
7171
#else
72-
unsetenv(name.toLatin1());
72+
unsetenv(name.toLocal8Bit());
7373
#endif
7474
}
7575

Base/ctkAppArguments.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void ctkChar2DArray::setValues(const QStringList& list)
5858
{
5959
QString item = d->List.at(index);
6060
d->Values[index] = new char[item.size() + 1];
61-
qstrcpy(d->Values[index], item.toLatin1().data());
61+
qstrcpy(d->Values[index], item.toLocal8Bit().data());
6262
}
6363
}
6464

Base/ctkAppLauncherEnvironment.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ void ctkAppLauncherEnvironment::updateCurrentEnvironment(const QProcessEnvironme
166166
foreach(const QString& varName, variablesToUnset)
167167
{
168168
#if defined(Q_OS_WIN32)
169-
bool success = qputenv(varName.toLatin1(), QString("").toLatin1());
169+
bool success = qputenv(varName.toLocal8Bit(), QString().toLocal8Bit());
170170
#else
171-
bool success = unsetenv(varName.toLatin1()) == EXIT_SUCCESS;
171+
bool success = unsetenv(varName.toLocal8Bit()) == EXIT_SUCCESS;
172172
#endif
173173
if (!success)
174174
{
@@ -180,7 +180,7 @@ void ctkAppLauncherEnvironment::updateCurrentEnvironment(const QProcessEnvironme
180180
foreach(const QString& varName, envKeys)
181181
{
182182
QString varValue = environment.value(varName);
183-
bool success = qputenv(varName.toLatin1(), varValue.toLatin1());
183+
bool success = qputenv(varName.toLocal8Bit(), varValue.toLocal8Bit());
184184
if (!success)
185185
{
186186
qWarning() << "Failed to set environment variable"

Base/ctkTest.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ static void mouseEvent(QTest::MouseAction action, QWidget *widget, Qt::MouseButt
9797
{
9898
static const char *mouseActionNames[] =
9999
{ "MousePress", "MouseRelease", "MouseClick", "MouseDClick", "MouseMove" };
100-
QString warning = QString::fromLatin1("Mouse event \"%1\" not accepted by receiving widget");
101-
QTest::qWarn(warning.arg(QString::fromLatin1(mouseActionNames[static_cast<int>(action)])).toLatin1());
100+
QString warning = QLatin1String("Mouse event \"%1\" not accepted by receiving widget");
101+
QTest::qWarn(warning.arg(QLatin1String(mouseActionNames[static_cast<int>(action)])).toLocal8Bit());
102102
}
103103
}
104104

0 commit comments

Comments
 (0)