summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <[email protected]>2024-12-31 16:26:39 -0300
committerThiago Macieira <[email protected]>2025-01-01 14:23:05 -0300
commitdb34e27f7f6ade54bfae59e5eed14c05ac508a49 (patch)
tree92ef99f5daa6d508644118fd8290bbbde363516b
parentce95c26034cc5b3ae8094c1521221e5b2f13ecfa (diff)
Replace qgetenv() calls converted to QString with qEnvironmentVariable()
It's slightly more efficient. Pick-to: 6.9 Change-Id: Id5ac04fc27eee108c8e5fffd786c3d5f793a0a9d Reviewed-by: Ahmad Samir <[email protected]>
-rw-r--r--src/corelib/global/qlogging.cpp2
-rw-r--r--src/corelib/io/qfilesystemengine_unix.cpp4
-rw-r--r--src/corelib/io/qloggingregistry.cpp5
-rw-r--r--src/corelib/io/qstandardpaths.cpp43
-rw-r--r--src/corelib/io/qstandardpaths_unix.cpp16
-rw-r--r--src/gui/image/qiconloader.cpp5
-rw-r--r--src/gui/kernel/qguiapplication.cpp2
-rw-r--r--src/gui/platform/unix/qgenericunixservices.cpp6
-rw-r--r--src/gui/platform/unix/qgenericunixthemes.cpp4
-rw-r--r--src/gui/text/qplatformfontdatabase.cpp2
-rw-r--r--src/gui/vulkan/qbasicvulkanplatforminstance.cpp2
-rw-r--r--src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager.cpp2
-rw-r--r--src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp2
-rw-r--r--src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp2
-rw-r--r--src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp2
-rw-r--r--src/platformsupport/input/shared/qoutputmapping.cpp8
-rw-r--r--src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.cpp8
-rw-r--r--src/plugins/platforms/eglfs/api/qeglfshooks.cpp16
-rw-r--r--src/plugins/platforms/xcb/qxcbintegration.cpp2
-rw-r--r--src/printsupport/kernel/qplatformprintplugin.cpp2
-rw-r--r--src/tools/uic/main.cpp2
-rw-r--r--src/widgets/dialogs/qfiledialog.cpp4
-rw-r--r--src/widgets/kernel/qapplication.cpp8
23 files changed, 75 insertions, 74 deletions
diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp
index 86800492511..d7b0f21b866 100644
--- a/src/corelib/global/qlogging.cpp
+++ b/src/corelib/global/qlogging.cpp
@@ -1186,7 +1186,7 @@ QMessagePattern::QMessagePattern()
#ifndef QT_BOOTSTRAPPED
timer.start();
#endif
- const QString envPattern = QString::fromLocal8Bit(qgetenv("QT_MESSAGE_PATTERN"));
+ const QString envPattern = qEnvironmentVariable("QT_MESSAGE_PATTERN");
if (envPattern.isEmpty()) {
setPattern(QLatin1StringView(defaultPattern));
fromEnvironment = false;
diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp
index 60963a1c9c2..ec962eba365 100644
--- a/src/corelib/io/qfilesystemengine_unix.cpp
+++ b/src/corelib/io/qfilesystemengine_unix.cpp
@@ -1783,7 +1783,7 @@ bool QFileSystemEngine::setFileTime(int fd, const QDateTime &newDate, QFile::Fil
QString QFileSystemEngine::homePath()
{
- QString home = QFile::decodeName(qgetenv("HOME"));
+ QString home = qEnvironmentVariable("HOME");
if (home.isEmpty())
home = rootPath();
return QDir::cleanPath(home);
@@ -1799,7 +1799,7 @@ QString QFileSystemEngine::tempPath()
#ifdef QT_UNIX_TEMP_PATH_OVERRIDE
return QT_UNIX_TEMP_PATH_OVERRIDE ""_L1;
#else
- QString temp = QFile::decodeName(qgetenv("TMPDIR"));
+ QString temp = qEnvironmentVariable("TMPDIR");
if (temp.isEmpty()) {
if (false) {
#if defined(Q_OS_DARWIN) && !defined(QT_BOOTSTRAPPED)
diff --git a/src/corelib/io/qloggingregistry.cpp b/src/corelib/io/qloggingregistry.cpp
index ee7b7c56132..32e8fdec659 100644
--- a/src/corelib/io/qloggingregistry.cpp
+++ b/src/corelib/io/qloggingregistry.cpp
@@ -282,9 +282,8 @@ void QLoggingRegistry::initializeRules()
}
QList<QLoggingRule> er, qr, cr;
// get rules from environment
- const QByteArray rulesFilePath = qgetenv("QT_LOGGING_CONF");
- if (!rulesFilePath.isEmpty())
- er = loadRulesFromFile(QFile::decodeName(rulesFilePath));
+ if (QString rulesFilePath = qEnvironmentVariable("QT_LOGGING_CONF"); !rulesFilePath.isEmpty())
+ er = loadRulesFromFile(rulesFilePath);
if (qtLoggingDebug())
debugMsg("Checking %s environment variable", "QT_LOGGING_RULES");
diff --git a/src/corelib/io/qstandardpaths.cpp b/src/corelib/io/qstandardpaths.cpp
index 792721f50d4..c0c676d04f2 100644
--- a/src/corelib/io/qstandardpaths.cpp
+++ b/src/corelib/io/qstandardpaths.cpp
@@ -6,6 +6,7 @@
#include <qdir.h>
#include <qfileinfo.h>
+#include <qvarlengtharray.h>
#ifndef QT_BOOTSTRAPPED
#include <qobject.h>
@@ -424,6 +425,28 @@ QStringList QStandardPaths::locateAll(StandardLocation type, const QString &file
return result;
}
+static Q_DECL_COLD_FUNCTION QString fallbackPathVariable()
+{
+#if defined(_PATH_DEFPATH)
+ // BSD API.
+ return QString::fromLocal8Bit(_PATH_DEFPATH);
+#endif
+#if defined(_CS_PATH)
+ // POSIX API.
+ size_t n = confstr(_CS_PATH, nullptr, 0);
+ if (n) {
+ // n includes the terminating null
+ QVarLengthArray<char, 1024> rawpath(n);
+ confstr(_CS_PATH, rawpath.data(), n);
+ return QString::fromLocal8Bit(QByteArrayView(rawpath.data(), n - 1));
+ }
+#else
+ // Windows SDK's execvpe() does not have a fallback, so we won't
+ // apply one either.
+#endif
+ return {};
+}
+
#ifdef Q_OS_WIN
static QStringList executableExtensions()
{
@@ -490,30 +513,16 @@ QString QStandardPaths::findExecutable(const QString &executableName, const QStr
QStringList searchPaths = paths;
if (paths.isEmpty()) {
- QByteArray pEnv = qgetenv("PATH");
+ QString pEnv = qEnvironmentVariable("PATH");
if (Q_UNLIKELY(pEnv.isNull())) {
// Get a default path. POSIX.1 does not actually require this, but
// most Unix libc fall back to confstr(_CS_PATH) if the PATH
// environment variable isn't set. Let's try to do the same.
-#if defined(_PATH_DEFPATH)
- // BSD API.
- pEnv = _PATH_DEFPATH;
-#elif defined(_CS_PATH)
- // POSIX API.
- size_t n = confstr(_CS_PATH, nullptr, 0);
- if (n) {
- pEnv.resize(n);
- // size()+1 is ok because QByteArray always has an extra NUL-terminator
- confstr(_CS_PATH, pEnv.data(), pEnv.size() + 1);
- }
-#else
- // Windows SDK's execvpe() does not have a fallback, so we won't
- // apply one either.
-#endif
+ pEnv = fallbackPathVariable();
}
// Remove trailing slashes, which occur on Windows.
- const QStringList rawPaths = QString::fromLocal8Bit(pEnv.constData()).split(
+ const QStringList rawPaths = pEnv.split(
QDir::listSeparator(), Qt::SkipEmptyParts);
searchPaths.reserve(rawPaths.size());
for (const QString &rawPath : rawPaths) {
diff --git a/src/corelib/io/qstandardpaths_unix.cpp b/src/corelib/io/qstandardpaths_unix.cpp
index e38f6708951..4fe8739bcc0 100644
--- a/src/corelib/io/qstandardpaths_unix.cpp
+++ b/src/corelib/io/qstandardpaths_unix.cpp
@@ -185,7 +185,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
xdgCacheHome = QDir::homePath() + "/.qttest/cache"_L1;
} else {
// http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html
- xdgCacheHome = QFile::decodeName(qgetenv("XDG_CACHE_HOME"));
+ xdgCacheHome = qEnvironmentVariable("XDG_CACHE_HOME");
if (!xdgCacheHome.startsWith(u'/'))
xdgCacheHome.clear(); // spec says relative paths should be ignored
@@ -204,7 +204,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
xdgStateHome = QDir::homePath() + "/.qttest/state"_L1;
} else {
// http://standards.freedesktop.org/basedir-spec/basedir-spec-0.8.html
- xdgStateHome = QFile::decodeName(qgetenv("XDG_STATE_HOME"));
+ xdgStateHome = qEnvironmentVariable("XDG_STATE_HOME");
if (!xdgStateHome.startsWith(u'/'))
xdgStateHome.clear(); // spec says relative paths should be ignored
@@ -223,7 +223,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
if (isTestModeEnabled()) {
xdgDataHome = QDir::homePath() + "/.qttest/share"_L1;
} else {
- xdgDataHome = QFile::decodeName(qgetenv("XDG_DATA_HOME"));
+ xdgDataHome = qEnvironmentVariable("XDG_DATA_HOME");
if (!xdgDataHome.startsWith(u'/'))
xdgDataHome.clear(); // spec says relative paths should be ignored
@@ -243,7 +243,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
xdgConfigHome = QDir::homePath() + "/.qttest/config"_L1;
} else {
// http://standards.freedesktop.org/basedir-spec/latest/
- xdgConfigHome = QFile::decodeName(qgetenv("XDG_CONFIG_HOME"));
+ xdgConfigHome = qEnvironmentVariable("XDG_CONFIG_HOME");
if (!xdgConfigHome.startsWith(u'/'))
xdgConfigHome.clear(); // spec says relative paths should be ignored
@@ -256,7 +256,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
}
case RuntimeLocation:
{
- QString xdgRuntimeDir = QFile::decodeName(qgetenv("XDG_RUNTIME_DIR"));
+ QString xdgRuntimeDir = qEnvironmentVariable("XDG_RUNTIME_DIR");
if (!xdgRuntimeDir.startsWith(u'/'))
xdgRuntimeDir.clear(); // spec says relative paths should be ignored
@@ -285,7 +285,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
#if QT_CONFIG(regularexpression)
// http://www.freedesktop.org/wiki/Software/xdg-user-dirs
- QString xdgConfigHome = QFile::decodeName(qgetenv("XDG_CONFIG_HOME"));
+ QString xdgConfigHome = qEnvironmentVariable("XDG_CONFIG_HOME");
if (!xdgConfigHome.startsWith(u'/'))
xdgConfigHome.clear(); // spec says relative paths should be ignored
@@ -390,7 +390,7 @@ static QStringList dirsList(const QString &xdgEnvVar)
static QStringList xdgDataDirs()
{
// http://standards.freedesktop.org/basedir-spec/latest/
- QString xdgDataDirsEnv = QFile::decodeName(qgetenv("XDG_DATA_DIRS"));
+ QString xdgDataDirsEnv = qEnvironmentVariable("XDG_DATA_DIRS");
QStringList dirs = dirsList(xdgDataDirsEnv);
if (dirs.isEmpty())
@@ -402,7 +402,7 @@ static QStringList xdgDataDirs()
static QStringList xdgConfigDirs()
{
// http://standards.freedesktop.org/basedir-spec/latest/
- const QString xdgConfigDirs = QFile::decodeName(qgetenv("XDG_CONFIG_DIRS"));
+ const QString xdgConfigDirs = qEnvironmentVariable("XDG_CONFIG_DIRS");
QStringList dirs = dirsList(xdgConfigDirs);
if (dirs.isEmpty())
diff --git a/src/gui/image/qiconloader.cpp b/src/gui/image/qiconloader.cpp
index 006b5f2793a..999c65bb438 100644
--- a/src/gui/image/qiconloader.cpp
+++ b/src/gui/image/qiconloader.cpp
@@ -50,9 +50,8 @@ QIconLoader::QIconLoader() :
static inline QString systemThemeName()
{
- const auto override = qgetenv("QT_QPA_SYSTEM_ICON_THEME");
- if (!override.isEmpty())
- return QString::fromLocal8Bit(override);
+ if (QString override = qEnvironmentVariable("QT_QPA_SYSTEM_ICON_THEME"); !override.isEmpty())
+ return override;
if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) {
const QVariant themeHint = theme->themeHint(QPlatformTheme::SystemIconThemeName);
if (themeHint.isValid())
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index dcdff702c44..0ca39d72451 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -1499,7 +1499,7 @@ void QGuiApplicationPrivate::createPlatformIntegration()
QHighDpiScaling::initHighDpiScaling();
// Load the platform integration
- QString platformPluginPath = QString::fromLocal8Bit(qgetenv("QT_QPA_PLATFORM_PLUGIN_PATH"));
+ QString platformPluginPath = qEnvironmentVariable("QT_QPA_PLATFORM_PLUGIN_PATH");
QByteArray platformName;
diff --git a/src/gui/platform/unix/qgenericunixservices.cpp b/src/gui/platform/unix/qgenericunixservices.cpp
index 32487b16511..a36976a6937 100644
--- a/src/gui/platform/unix/qgenericunixservices.cpp
+++ b/src/gui/platform/unix/qgenericunixservices.cpp
@@ -105,10 +105,10 @@ static inline bool detectWebBrowser(const QByteArray &desktop,
return true;
if (checkBrowserVariable) {
- QByteArray browserVariable = qgetenv("DEFAULT_BROWSER");
+ QString browserVariable = qEnvironmentVariable("DEFAULT_BROWSER");
if (browserVariable.isEmpty())
- browserVariable = qgetenv("BROWSER");
- if (!browserVariable.isEmpty() && checkExecutable(QString::fromLocal8Bit(browserVariable), browser))
+ browserVariable = qEnvironmentVariable("BROWSER");
+ if (!browserVariable.isEmpty() && checkExecutable(browserVariable, browser))
return true;
}
diff --git a/src/gui/platform/unix/qgenericunixthemes.cpp b/src/gui/platform/unix/qgenericunixthemes.cpp
index cd916bcf7a2..e2037639a4d 100644
--- a/src/gui/platform/unix/qgenericunixthemes.cpp
+++ b/src/gui/platform/unix/qgenericunixthemes.cpp
@@ -1204,11 +1204,11 @@ QPlatformTheme *QKdeTheme::createKdeTheme()
// - fallback to /etc/kde<version>
QStringList kdeDirs;
- const QString kdeHomePathVar = QFile::decodeName(qgetenv("KDEHOME"));
+ const QString kdeHomePathVar = qEnvironmentVariable("KDEHOME");
if (!kdeHomePathVar.isEmpty())
kdeDirs += kdeHomePathVar;
- const QString kdeDirsVar = QFile::decodeName(qgetenv("KDEDIRS"));
+ const QString kdeDirsVar = qEnvironmentVariable("KDEDIRS");
if (!kdeDirsVar.isEmpty())
kdeDirs += kdeDirsVar.split(u':', Qt::SkipEmptyParts);
diff --git a/src/gui/text/qplatformfontdatabase.cpp b/src/gui/text/qplatformfontdatabase.cpp
index 3d3f3c30985..381431ac4e9 100644
--- a/src/gui/text/qplatformfontdatabase.cpp
+++ b/src/gui/text/qplatformfontdatabase.cpp
@@ -360,7 +360,7 @@ void QPlatformFontDatabase::releaseHandle(void *handle)
*/
QString QPlatformFontDatabase::fontDir() const
{
- QString fontpath = QString::fromLocal8Bit(qgetenv("QT_QPA_FONTDIR"));
+ QString fontpath = qEnvironmentVariable("QT_QPA_FONTDIR");
if (fontpath.isEmpty())
fontpath = QLibraryInfo::path(QLibraryInfo::LibrariesPath) + "/fonts"_L1;
diff --git a/src/gui/vulkan/qbasicvulkanplatforminstance.cpp b/src/gui/vulkan/qbasicvulkanplatforminstance.cpp
index b6a820199c0..47d9a7e962f 100644
--- a/src/gui/vulkan/qbasicvulkanplatforminstance.cpp
+++ b/src/gui/vulkan/qbasicvulkanplatforminstance.cpp
@@ -51,7 +51,7 @@ void QBasicPlatformVulkanInstance::loadVulkanLibrary(const QString &defaultLibra
// embedded systems without a Vulkan loader and possibly with custom vendor
// library names.
if (qEnvironmentVariableIsSet("QT_VULKAN_LIB"))
- loadList.append({ QString::fromUtf8(qgetenv("QT_VULKAN_LIB")), -1 });
+ loadList.append({ qEnvironmentVariable("QT_VULKAN_LIB"), -1 });
// Then what the platform specified. On Linux the version is likely 1, thus
// preferring libvulkan.so.1 over libvulkan.so.
diff --git a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager.cpp b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager.cpp
index 8fcf01ae902..da82cf12b7d 100644
--- a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager.cpp
+++ b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager.cpp
@@ -22,7 +22,7 @@ QEvdevKeyboardManager::QEvdevKeyboardManager(const QString &key, const QString &
Q_UNUSED(key);
- QString spec = QString::fromLocal8Bit(qgetenv("QT_QPA_EVDEV_KEYBOARD_PARAMETERS"));
+ QString spec = qEnvironmentVariable("QT_QPA_EVDEV_KEYBOARD_PARAMETERS");
if (spec.isEmpty())
spec = specification;
diff --git a/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp b/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp
index 83176a17931..a9619a53c6b 100644
--- a/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp
+++ b/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp
@@ -24,7 +24,7 @@ QEvdevMouseManager::QEvdevMouseManager(const QString &key, const QString &specif
{
Q_UNUSED(key);
- QString spec = QString::fromLocal8Bit(qgetenv("QT_QPA_EVDEV_MOUSE_PARAMETERS"));
+ QString spec = qEnvironmentVariable("QT_QPA_EVDEV_MOUSE_PARAMETERS");
if (spec.isEmpty())
spec = specification;
diff --git a/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp b/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp
index d013ef04d50..6395e57c127 100644
--- a/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp
+++ b/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp
@@ -23,7 +23,7 @@ QEvdevTabletManager::QEvdevTabletManager(const QString &key, const QString &spec
if (qEnvironmentVariableIsSet("QT_QPA_EVDEV_DEBUG"))
const_cast<QLoggingCategory &>(qLcEvdevTablet()).setEnabled(QtDebugMsg, true);
- QString spec = QString::fromLocal8Bit(qgetenv("QT_QPA_EVDEV_TABLET_PARAMETERS"));
+ QString spec = qEnvironmentVariable("QT_QPA_EVDEV_TABLET_PARAMETERS");
if (spec.isEmpty())
spec = specification;
diff --git a/src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp b/src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp
index bd9a3cc6767..dbfe1bad080 100644
--- a/src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp
+++ b/src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp
@@ -23,7 +23,7 @@ QEvdevTouchManager::QEvdevTouchManager(const QString &key, const QString &specif
if (qEnvironmentVariableIsSet("QT_QPA_EVDEV_DEBUG"))
const_cast<QLoggingCategory &>(qLcEvdevTouch()).setEnabled(QtDebugMsg, true);
- QString spec = QString::fromLocal8Bit(qgetenv("QT_QPA_EVDEV_TOUCHSCREEN_PARAMETERS"));
+ QString spec = qEnvironmentVariable("QT_QPA_EVDEV_TOUCHSCREEN_PARAMETERS");
if (spec.isEmpty())
spec = specification;
diff --git a/src/platformsupport/input/shared/qoutputmapping.cpp b/src/platformsupport/input/shared/qoutputmapping.cpp
index c8683958d3c..3b9f6208c42 100644
--- a/src/platformsupport/input/shared/qoutputmapping.cpp
+++ b/src/platformsupport/input/shared/qoutputmapping.cpp
@@ -52,19 +52,19 @@ void QOutputMapping::set(QOutputMapping *mapping)
bool QDefaultOutputMapping::load()
{
- static QByteArray configFile = qgetenv("QT_QPA_EGLFS_KMS_CONFIG");
+ static QString configFile = qEnvironmentVariable("QT_QPA_EGLFS_KMS_CONFIG");
if (configFile.isEmpty())
return false;
- QFile file(QString::fromUtf8(configFile));
+ QFile file(configFile);
if (!file.open(QFile::ReadOnly)) {
- qWarning("touch input support: Failed to open %s", configFile.constData());
+ qWarning("touch input support: Failed to open %ls", qUtf16Printable(configFile));
return false;
}
const QJsonDocument doc = QJsonDocument::fromJson(file.readAll());
if (!doc.isObject()) {
- qWarning("touch input support: Failed to parse %s", configFile.constData());
+ qWarning("touch input support: Failed to parse %ls", qUtf16Printable(configFile));
return false;
}
diff --git a/src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.cpp b/src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.cpp
index c38cb289c19..d59a6689592 100644
--- a/src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.cpp
+++ b/src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.cpp
@@ -731,11 +731,9 @@ QString QIBusPlatformInputContextPrivate::getSocketPath()
QByteArray displayNumber = "0";
bool isWayland = false;
- if (qEnvironmentVariableIsSet("IBUS_ADDRESS_FILE")) {
- QByteArray path = qgetenv("IBUS_ADDRESS_FILE");
- return QString::fromLocal8Bit(path);
- } else if (qEnvironmentVariableIsSet("WAYLAND_DISPLAY")) {
- display = qgetenv("WAYLAND_DISPLAY");
+ if (QString path = qEnvironmentVariable("IBUS_ADDRESS_FILE"); !path.isNull()) {
+ return path;
+ } else if (display = qgetenv("WAYLAND_DISPLAY"); !display.isEmpty()) {
isWayland = true;
} else {
display = qgetenv("DISPLAY");
diff --git a/src/plugins/platforms/eglfs/api/qeglfshooks.cpp b/src/plugins/platforms/eglfs/api/qeglfshooks.cpp
index 6918d73ffeb..99839fce86b 100644
--- a/src/plugins/platforms/eglfs/api/qeglfshooks.cpp
+++ b/src/plugins/platforms/eglfs/api/qeglfshooks.cpp
@@ -50,29 +50,25 @@ DeviceIntegration::DeviceIntegration()
}
}
- QByteArray requested;
-
// The environment variable can override everything.
- if (qEnvironmentVariableIsSet("QT_QPA_EGLFS_INTEGRATION")) {
- requested = qgetenv("QT_QPA_EGLFS_INTEGRATION");
- } else {
+ QString requested = qEnvironmentVariable("QT_QPA_EGLFS_INTEGRATION");
+ if (requested.isNull()) {
// Device-specific makespecs may define a preferred plugin.
#ifdef EGLFS_PREFERRED_PLUGIN
#define DEFAULT_PLUGIN EGLFS_PREFERRED_PLUGIN
#define STR(s) #s
#define STRQ(s) STR(s)
- requested = STRQ(DEFAULT_PLUGIN);
+ requested = QStringLiteral(STRQ(DEFAULT_PLUGIN));
#endif
}
// Treat "none" as special. There has to be a way to indicate
// that plugins must be ignored when the device is known to be
// functional with the default, non-specialized integration.
- if (requested != QByteArrayLiteral("none")) {
+ if (requested != QStringLiteral("none")) {
if (!requested.isEmpty()) {
- QString reqStr = QString::fromLocal8Bit(requested);
- pluginKeys.removeOne(reqStr);
- pluginKeys.prepend(reqStr);
+ pluginKeys.removeOne(requested);
+ pluginKeys.prepend(requested);
}
qCDebug(qLcEglDevDebug) << "EGL device integration plugin keys (sorted):" << pluginKeys;
while (!m_integration && !pluginKeys.isEmpty()) {
diff --git a/src/plugins/platforms/xcb/qxcbintegration.cpp b/src/plugins/platforms/xcb/qxcbintegration.cpp
index fc5a7e55c50..2c28de316f7 100644
--- a/src/plugins/platforms/xcb/qxcbintegration.cpp
+++ b/src/plugins/platforms/xcb/qxcbintegration.cpp
@@ -531,7 +531,7 @@ QByteArray QXcbIntegration::wmClass() const
if (m_instanceName)
name = QString::fromLocal8Bit(m_instanceName);
if (name.isEmpty() && qEnvironmentVariableIsSet(resourceNameVar))
- name = QString::fromLocal8Bit(qgetenv(resourceNameVar));
+ name = qEnvironmentVariable(resourceNameVar);
if (name.isEmpty())
name = argv0BaseName();
diff --git a/src/printsupport/kernel/qplatformprintplugin.cpp b/src/printsupport/kernel/qplatformprintplugin.cpp
index c48e5f65bfc..37222eb039d 100644
--- a/src/printsupport/kernel/qplatformprintplugin.cpp
+++ b/src/printsupport/kernel/qplatformprintplugin.cpp
@@ -54,7 +54,7 @@ QPlatformPrinterSupport *QPlatformPrinterSupportPlugin::get()
const QMultiMap<int, QString> keyMap = loader()->keyMap();
QMultiMap<int, QString>::const_iterator it = keyMap.cbegin();
if (!qEnvironmentVariableIsEmpty("QT_PRINTER_MODULE")) {
- QString module = QString::fromLocal8Bit(qgetenv("QT_PRINTER_MODULE"));
+ QString module = qEnvironmentVariable("QT_PRINTER_MODULE");
QMultiMap<int, QString>::const_iterator it2 = std::find_if(keyMap.cbegin(), keyMap.cend(), [module](const QString &value){ return value == module; });
if (it2 == keyMap.cend())
qWarning() << "Unable to load printer plugin" << module;
diff --git a/src/tools/uic/main.cpp b/src/tools/uic/main.cpp
index d46b788419c..9f995a85d40 100644
--- a/src/tools/uic/main.cpp
+++ b/src/tools/uic/main.cpp
@@ -187,7 +187,7 @@ int runUic(int argc, char *argv[])
if (parser.isSet(pythonPathOption))
pythonPaths = parser.value(pythonPathOption);
else if (qEnvironmentVariableIsSet(pythonPathVar))
- pythonPaths = QString::fromUtf8(qgetenv(pythonPathVar));
+ pythonPaths = qEnvironmentVariable(pythonPathVar);
driver.option().pythonRoot = pythonRoot(pythonPaths, inputFile);
}
diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp
index d414cbf841f..d52d678243e 100644
--- a/src/widgets/dialogs/qfiledialog.cpp
+++ b/src/widgets/dialogs/qfiledialog.cpp
@@ -3995,11 +3995,11 @@ QString QFileDialogPrivate::getEnvironmentVariable(const QString &string)
{
#ifdef Q_OS_UNIX
if (string.size() > 1 && string.startsWith(u'$')) {
- return QString::fromLocal8Bit(qgetenv(QStringView{string}.mid(1).toLatin1().constData()));
+ return qEnvironmentVariable(QStringView{string}.mid(1).toLatin1().constData());
}
#else
if (string.size() > 2 && string.startsWith(u'%') && string.endsWith(u'%')) {
- return QString::fromLocal8Bit(qgetenv(QStringView{string}.mid(1, string.size() - 2).toLatin1().constData()));
+ return qEnvironmentVariable(QStringView{string}.mid(1, string.size() - 2).toLatin1().constData());
}
#endif
return string;
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp
index 37be88927e6..95e1761d3e9 100644
--- a/src/widgets/kernel/qapplication.cpp
+++ b/src/widgets/kernel/qapplication.cpp
@@ -363,8 +363,8 @@ QWidget *qt_desktopWidget = nullptr; // root window widgets
*/
void QApplicationPrivate::process_cmdline()
{
- if (styleOverride.isEmpty() && qEnvironmentVariableIsSet("QT_STYLE_OVERRIDE"))
- styleOverride = QString::fromLocal8Bit(qgetenv("QT_STYLE_OVERRIDE"));
+ if (styleOverride.isEmpty())
+ styleOverride = qEnvironmentVariable("QT_STYLE_OVERRIDE");
// process platform-indep command line
if (qt_is_tty_app || !argc)
@@ -1411,8 +1411,8 @@ QString QApplicationPrivate::desktopStyleKey()
{
#if defined(QT_BUILD_INTERNAL)
// Allow auto-tests to override the desktop style
- if (qEnvironmentVariableIsSet("QT_DESKTOP_STYLE_KEY"))
- return QString::fromLocal8Bit(qgetenv("QT_DESKTOP_STYLE_KEY"));
+ if (QString env = qEnvironmentVariable("QT_DESKTOP_STYLE_KEY"); !env.isNull())
+ return env;
#endif
// The platform theme might return a style that is not available, find