diff --git a/src/libs/utils/devicefileaccess.cpp b/src/libs/utils/devicefileaccess.cpp index 24d69f728b7..b7e7edf24a7 100644 --- a/src/libs/utils/devicefileaccess.cpp +++ b/src/libs/utils/devicefileaccess.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #ifdef Q_OS_WIN @@ -400,6 +401,18 @@ Utils::expected_str> DeviceFileAccess::watch( return make_unexpected(Tr::tr("watch is not implemented.")); } +QTextCodec *DeviceFileAccess::processStdOutCodec(const FilePath &executable) const +{ + Q_UNUSED(executable) + return QTextCodec::codecForName("UTF-8"); // Good default nowadays. +} + +QTextCodec *DeviceFileAccess::processStdErrCodec(const FilePath &executable) const +{ + Q_UNUSED(executable) + return QTextCodec::codecForName("UTF-8"); // Good default nowadays. +} + // UnavailableDeviceFileAccess UnavailableDeviceFileAccess::UnavailableDeviceFileAccess() = default; @@ -1183,6 +1196,18 @@ Utils::expected_str> DesktopDeviceFileAccess::w return make_unexpected(watcher->error()); } +QTextCodec *DesktopDeviceFileAccess::processStdOutCodec(const FilePath &executable) const +{ + Q_UNUSED(executable); + return QTextCodec::codecForLocale(); +} + +QTextCodec *DesktopDeviceFileAccess::processStdErrCodec(const FilePath &executable) const +{ + Q_UNUSED(executable); + return QTextCodec::codecForLocale(); +} + QDateTime DesktopDeviceFileAccess::lastModified(const FilePath &filePath) const { return QFileInfo(filePath.path()).lastModified(); diff --git a/src/libs/utils/devicefileaccess.h b/src/libs/utils/devicefileaccess.h index 04931046472..1a49a48259f 100644 --- a/src/libs/utils/devicefileaccess.h +++ b/src/libs/utils/devicefileaccess.h @@ -10,6 +10,10 @@ class tst_unixdevicefileaccess; // For testing. +QT_BEGIN_NAMESPACE +class QTextCodec; +QT_END_NAMESPACE + namespace Utils { class CommandLine; @@ -77,6 +81,9 @@ protected: virtual expected_str createTempFile(const FilePath &filePath); virtual Utils::expected_str> watch(const FilePath &path) const; + + virtual QTextCodec *processStdOutCodec(const FilePath &executable) const; + virtual QTextCodec *processStdErrCodec(const FilePath &executable) const; }; class QTCREATOR_UTILS_EXPORT UnavailableDeviceFileAccess : public DeviceFileAccess @@ -194,6 +201,9 @@ protected: expected_str createTempFile(const FilePath &filePath) override; Utils::expected_str> watch(const FilePath &path) const override; + + QTextCodec *processStdOutCodec(const FilePath &executable) const override; + QTextCodec *processStdErrCodec(const FilePath &executable) const override; }; class QTCREATOR_UTILS_EXPORT UnixDeviceFileAccess : public DeviceFileAccess diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp index e617ddf1eb3..5bfa0a9b0e8 100644 --- a/src/libs/utils/filepath.cpp +++ b/src/libs/utils/filepath.cpp @@ -2155,6 +2155,16 @@ QChar FilePath::pathListSeparator() const return osType() == OsTypeWindows ? u';' : u':'; } +QTextCodec *FilePath::processStdOutCodec() const +{ + return fileAccess()->processStdOutCodec(*this); +} + +QTextCodec *FilePath::processStdErrCodec() const +{ + return fileAccess()->processStdErrCodec(*this); +} + /*! \brief Recursively resolves symlinks if this is a symlink. diff --git a/src/libs/utils/filepath.h b/src/libs/utils/filepath.h index 36ab6ad532f..07bd00b9d81 100644 --- a/src/libs/utils/filepath.h +++ b/src/libs/utils/filepath.h @@ -24,6 +24,7 @@ QT_BEGIN_NAMESPACE class QDateTime; class QDebug; class QFileInfo; +class QTextCodec; class QUrl; QT_END_NAMESPACE @@ -191,6 +192,9 @@ public: QChar pathComponentSeparator() const; QChar pathListSeparator() const; + QTextCodec *processStdOutCodec() const; + QTextCodec *processStdErrCodec() const; + void clear(); bool isEmpty() const;