From f22bc3f540c9664fd90e6675b39174ec8d3f6b1c Mon Sep 17 00:00:00 2001 From: askmeaboutloom Date: Tue, 12 Nov 2024 15:18:24 +0100 Subject: [PATCH] Reset locale to "C" on Unix systems After Qt messes it up when you initialze a QCoreApplication or similar. --- ChangeLog | 1 + src/desktop/main.cpp | 2 ++ src/drawdance/libcommon/dpcommon/platform_qt.h | 14 ++++++++++++++ src/thinsrv/main.cpp | 3 ++- src/tools/drawpile-timelapse/main.cpp | 1 + 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 0ff05ec665..7dc9acd3ba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ Unreleased Version 2.2.2-pre * Fix: Make temporary tool switches by holding a key down work again. Thanks 3rd_EFNO and bunnie for reporting. * Fix: Disregard hidden layers when layer picking in frame view. * Feature: Add a search bar to the key frame properties dialog. + * Fix: Reset locale to "C" after Qt messes it up on startup. Thanks Meru for reporting. 2024-11-06 Version 2.2.2-beta.4 * Fix: Solve rendering glitches with selection outlines that happen on some systems. Thanks xxxx for reporting. diff --git a/src/desktop/main.cpp b/src/desktop/main.cpp index 7449533be9..2af2ffad95 100644 --- a/src/desktop/main.cpp +++ b/src/desktop/main.cpp @@ -9,6 +9,7 @@ #include "desktop/utils/globalkeyeventfilter.h" #include "desktop/utils/qtguicompat.h" #include "desktop/utils/recents.h" +#include "dpcommon/platform_qt.h" #include "libclient/brushes/brushpresetmodel.h" #include "libclient/drawdance/global.h" #include "libclient/utils/colorscheme.h" @@ -1125,6 +1126,7 @@ extern "C" void drawpileMain(int argc, char **argv) DrawpileApp appInstance(argc, argv); DrawpileApp *app = &appInstance; #endif + DP_QT_LOCALE_RESET(); compat::disableImageReaderAllocationLimit(); startApplication(app); diff --git a/src/drawdance/libcommon/dpcommon/platform_qt.h b/src/drawdance/libcommon/dpcommon/platform_qt.h index f43371c16e..62c901441a 100644 --- a/src/drawdance/libcommon/dpcommon/platform_qt.h +++ b/src/drawdance/libcommon/dpcommon/platform_qt.h @@ -3,6 +3,20 @@ #define DPCOMMON_PLATFORM_H #include +// On Unix systems, Qt messes up the locale on startup. +#ifdef Q_OS_UNIX +# include +# define DP_QT_LOCALE_RESET() \ + do { \ + setlocale(LC_ALL, "C"); \ + } while (0) +#else +# define DP_QT_LOCALE_RESET() \ + do { \ + /* nothing */ \ + } while (0) +#endif + // On Android, files don't get truncated when writing without the truncate flag. static constexpr QIODevice::OpenMode DP_QT_WRITE_FLAGS = #ifdef Q_OS_ANDROID diff --git a/src/thinsrv/main.cpp b/src/thinsrv/main.cpp index 30f1c64a38..80f268214c 100644 --- a/src/thinsrv/main.cpp +++ b/src/thinsrv/main.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include "cmake-config/config.h" +#include "dpcommon/platform_qt.h" #include "libserver/jsonapi.h" // for datatype registration #include "thinsrv/headless/headless.h" #include "thinsrv/initsys.h" @@ -56,7 +57,7 @@ int main(int argc, char *argv[]) #else app.reset(new QCoreApplication(argc, argv)); #endif - + DP_QT_LOCALE_RESET(); // Set common settings QCoreApplication::setOrganizationName("drawpile"); diff --git a/src/tools/drawpile-timelapse/main.cpp b/src/tools/drawpile-timelapse/main.cpp index 681ea92dae..36416ceb9b 100644 --- a/src/tools/drawpile-timelapse/main.cpp +++ b/src/tools/drawpile-timelapse/main.cpp @@ -51,6 +51,7 @@ static QString writeDefaultLogo() int main(int argc, char **argv) { QCoreApplication app(argc, argv); + DP_QT_LOCALE_RESET(); app.setOrganizationName("drawpile"); app.setOrganizationDomain("drawpile.net"); app.setApplicationName("drawpile-timelapse");