Replace qgetenv() calls converted to QString with qEnvironmentVariable()

It's slightly more efficient.

Change-Id: Id5ac04fc27eee108c8e5fffd786c3d5f793a0a9d
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
(cherry picked from commit db34e27f7f6ade54bfae59e5eed14c05ac508a49)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Thiago Macieira 2024-12-31 16:26:39 -03:00 committed by Qt Cherry-pick Bot
parent 36d260014f
commit 381dca29ff
23 changed files with 75 additions and 74 deletions

View File

@ -1186,7 +1186,7 @@ QMessagePattern::QMessagePattern()
#ifndef QT_BOOTSTRAPPED #ifndef QT_BOOTSTRAPPED
timer.start(); timer.start();
#endif #endif
const QString envPattern = QString::fromLocal8Bit(qgetenv("QT_MESSAGE_PATTERN")); const QString envPattern = qEnvironmentVariable("QT_MESSAGE_PATTERN");
if (envPattern.isEmpty()) { if (envPattern.isEmpty()) {
setPattern(QLatin1StringView(defaultPattern)); setPattern(QLatin1StringView(defaultPattern));
fromEnvironment = false; fromEnvironment = false;

View File

@ -1783,7 +1783,7 @@ bool QFileSystemEngine::setFileTime(int fd, const QDateTime &newDate, QFile::Fil
QString QFileSystemEngine::homePath() QString QFileSystemEngine::homePath()
{ {
QString home = QFile::decodeName(qgetenv("HOME")); QString home = qEnvironmentVariable("HOME");
if (home.isEmpty()) if (home.isEmpty())
home = rootPath(); home = rootPath();
return QDir::cleanPath(home); return QDir::cleanPath(home);
@ -1799,7 +1799,7 @@ QString QFileSystemEngine::tempPath()
#ifdef QT_UNIX_TEMP_PATH_OVERRIDE #ifdef QT_UNIX_TEMP_PATH_OVERRIDE
return QT_UNIX_TEMP_PATH_OVERRIDE ""_L1; return QT_UNIX_TEMP_PATH_OVERRIDE ""_L1;
#else #else
QString temp = QFile::decodeName(qgetenv("TMPDIR")); QString temp = qEnvironmentVariable("TMPDIR");
if (temp.isEmpty()) { if (temp.isEmpty()) {
if (false) { if (false) {
#if defined(Q_OS_DARWIN) && !defined(QT_BOOTSTRAPPED) #if defined(Q_OS_DARWIN) && !defined(QT_BOOTSTRAPPED)

View File

@ -282,9 +282,8 @@ void QLoggingRegistry::initializeRules()
} }
QList<QLoggingRule> er, qr, cr; QList<QLoggingRule> er, qr, cr;
// get rules from environment // get rules from environment
const QByteArray rulesFilePath = qgetenv("QT_LOGGING_CONF"); if (QString rulesFilePath = qEnvironmentVariable("QT_LOGGING_CONF"); !rulesFilePath.isEmpty())
if (!rulesFilePath.isEmpty()) er = loadRulesFromFile(rulesFilePath);
er = loadRulesFromFile(QFile::decodeName(rulesFilePath));
if (qtLoggingDebug()) if (qtLoggingDebug())
debugMsg("Checking %s environment variable", "QT_LOGGING_RULES"); debugMsg("Checking %s environment variable", "QT_LOGGING_RULES");

View File

@ -6,6 +6,7 @@
#include <qdir.h> #include <qdir.h>
#include <qfileinfo.h> #include <qfileinfo.h>
#include <qvarlengtharray.h>
#ifndef QT_BOOTSTRAPPED #ifndef QT_BOOTSTRAPPED
#include <qobject.h> #include <qobject.h>
@ -424,6 +425,28 @@ QStringList QStandardPaths::locateAll(StandardLocation type, const QString &file
return result; 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 #ifdef Q_OS_WIN
static QStringList executableExtensions() static QStringList executableExtensions()
{ {
@ -490,30 +513,16 @@ QString QStandardPaths::findExecutable(const QString &executableName, const QStr
QStringList searchPaths = paths; QStringList searchPaths = paths;
if (paths.isEmpty()) { if (paths.isEmpty()) {
QByteArray pEnv = qgetenv("PATH"); QString pEnv = qEnvironmentVariable("PATH");
if (Q_UNLIKELY(pEnv.isNull())) { if (Q_UNLIKELY(pEnv.isNull())) {
// Get a default path. POSIX.1 does not actually require this, but // Get a default path. POSIX.1 does not actually require this, but
// most Unix libc fall back to confstr(_CS_PATH) if the PATH // most Unix libc fall back to confstr(_CS_PATH) if the PATH
// environment variable isn't set. Let's try to do the same. // environment variable isn't set. Let's try to do the same.
#if defined(_PATH_DEFPATH) pEnv = fallbackPathVariable();
// 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
} }
// Remove trailing slashes, which occur on Windows. // Remove trailing slashes, which occur on Windows.
const QStringList rawPaths = QString::fromLocal8Bit(pEnv.constData()).split( const QStringList rawPaths = pEnv.split(
QDir::listSeparator(), Qt::SkipEmptyParts); QDir::listSeparator(), Qt::SkipEmptyParts);
searchPaths.reserve(rawPaths.size()); searchPaths.reserve(rawPaths.size());
for (const QString &rawPath : rawPaths) { for (const QString &rawPath : rawPaths) {

View File

@ -185,7 +185,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
xdgCacheHome = QDir::homePath() + "/.qttest/cache"_L1; xdgCacheHome = QDir::homePath() + "/.qttest/cache"_L1;
} else { } else {
// http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html // 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'/')) if (!xdgCacheHome.startsWith(u'/'))
xdgCacheHome.clear(); // spec says relative paths should be ignored xdgCacheHome.clear(); // spec says relative paths should be ignored
@ -204,7 +204,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
xdgStateHome = QDir::homePath() + "/.qttest/state"_L1; xdgStateHome = QDir::homePath() + "/.qttest/state"_L1;
} else { } else {
// http://standards.freedesktop.org/basedir-spec/basedir-spec-0.8.html // 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'/')) if (!xdgStateHome.startsWith(u'/'))
xdgStateHome.clear(); // spec says relative paths should be ignored xdgStateHome.clear(); // spec says relative paths should be ignored
@ -223,7 +223,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
if (isTestModeEnabled()) { if (isTestModeEnabled()) {
xdgDataHome = QDir::homePath() + "/.qttest/share"_L1; xdgDataHome = QDir::homePath() + "/.qttest/share"_L1;
} else { } else {
xdgDataHome = QFile::decodeName(qgetenv("XDG_DATA_HOME")); xdgDataHome = qEnvironmentVariable("XDG_DATA_HOME");
if (!xdgDataHome.startsWith(u'/')) if (!xdgDataHome.startsWith(u'/'))
xdgDataHome.clear(); // spec says relative paths should be ignored xdgDataHome.clear(); // spec says relative paths should be ignored
@ -243,7 +243,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
xdgConfigHome = QDir::homePath() + "/.qttest/config"_L1; xdgConfigHome = QDir::homePath() + "/.qttest/config"_L1;
} else { } else {
// http://standards.freedesktop.org/basedir-spec/latest/ // http://standards.freedesktop.org/basedir-spec/latest/
xdgConfigHome = QFile::decodeName(qgetenv("XDG_CONFIG_HOME")); xdgConfigHome = qEnvironmentVariable("XDG_CONFIG_HOME");
if (!xdgConfigHome.startsWith(u'/')) if (!xdgConfigHome.startsWith(u'/'))
xdgConfigHome.clear(); // spec says relative paths should be ignored xdgConfigHome.clear(); // spec says relative paths should be ignored
@ -256,7 +256,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
} }
case RuntimeLocation: case RuntimeLocation:
{ {
QString xdgRuntimeDir = QFile::decodeName(qgetenv("XDG_RUNTIME_DIR")); QString xdgRuntimeDir = qEnvironmentVariable("XDG_RUNTIME_DIR");
if (!xdgRuntimeDir.startsWith(u'/')) if (!xdgRuntimeDir.startsWith(u'/'))
xdgRuntimeDir.clear(); // spec says relative paths should be ignored xdgRuntimeDir.clear(); // spec says relative paths should be ignored
@ -285,7 +285,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
#if QT_CONFIG(regularexpression) #if QT_CONFIG(regularexpression)
// http://www.freedesktop.org/wiki/Software/xdg-user-dirs // 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'/')) if (!xdgConfigHome.startsWith(u'/'))
xdgConfigHome.clear(); // spec says relative paths should be ignored xdgConfigHome.clear(); // spec says relative paths should be ignored
@ -390,7 +390,7 @@ static QStringList dirsList(const QString &xdgEnvVar)
static QStringList xdgDataDirs() static QStringList xdgDataDirs()
{ {
// http://standards.freedesktop.org/basedir-spec/latest/ // 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); QStringList dirs = dirsList(xdgDataDirsEnv);
if (dirs.isEmpty()) if (dirs.isEmpty())
@ -402,7 +402,7 @@ static QStringList xdgDataDirs()
static QStringList xdgConfigDirs() static QStringList xdgConfigDirs()
{ {
// http://standards.freedesktop.org/basedir-spec/latest/ // 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); QStringList dirs = dirsList(xdgConfigDirs);
if (dirs.isEmpty()) if (dirs.isEmpty())

View File

@ -50,9 +50,8 @@ QIconLoader::QIconLoader() :
static inline QString systemThemeName() static inline QString systemThemeName()
{ {
const auto override = qgetenv("QT_QPA_SYSTEM_ICON_THEME"); if (QString override = qEnvironmentVariable("QT_QPA_SYSTEM_ICON_THEME"); !override.isEmpty())
if (!override.isEmpty()) return override;
return QString::fromLocal8Bit(override);
if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) { if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) {
const QVariant themeHint = theme->themeHint(QPlatformTheme::SystemIconThemeName); const QVariant themeHint = theme->themeHint(QPlatformTheme::SystemIconThemeName);
if (themeHint.isValid()) if (themeHint.isValid())

View File

@ -1499,7 +1499,7 @@ void QGuiApplicationPrivate::createPlatformIntegration()
QHighDpiScaling::initHighDpiScaling(); QHighDpiScaling::initHighDpiScaling();
// Load the platform integration // Load the platform integration
QString platformPluginPath = QString::fromLocal8Bit(qgetenv("QT_QPA_PLATFORM_PLUGIN_PATH")); QString platformPluginPath = qEnvironmentVariable("QT_QPA_PLATFORM_PLUGIN_PATH");
QByteArray platformName; QByteArray platformName;

View File

@ -105,10 +105,10 @@ static inline bool detectWebBrowser(const QByteArray &desktop,
return true; return true;
if (checkBrowserVariable) { if (checkBrowserVariable) {
QByteArray browserVariable = qgetenv("DEFAULT_BROWSER"); QString browserVariable = qEnvironmentVariable("DEFAULT_BROWSER");
if (browserVariable.isEmpty()) if (browserVariable.isEmpty())
browserVariable = qgetenv("BROWSER"); browserVariable = qEnvironmentVariable("BROWSER");
if (!browserVariable.isEmpty() && checkExecutable(QString::fromLocal8Bit(browserVariable), browser)) if (!browserVariable.isEmpty() && checkExecutable(browserVariable, browser))
return true; return true;
} }

View File

@ -1204,11 +1204,11 @@ QPlatformTheme *QKdeTheme::createKdeTheme()
// - fallback to /etc/kde<version> // - fallback to /etc/kde<version>
QStringList kdeDirs; QStringList kdeDirs;
const QString kdeHomePathVar = QFile::decodeName(qgetenv("KDEHOME")); const QString kdeHomePathVar = qEnvironmentVariable("KDEHOME");
if (!kdeHomePathVar.isEmpty()) if (!kdeHomePathVar.isEmpty())
kdeDirs += kdeHomePathVar; kdeDirs += kdeHomePathVar;
const QString kdeDirsVar = QFile::decodeName(qgetenv("KDEDIRS")); const QString kdeDirsVar = qEnvironmentVariable("KDEDIRS");
if (!kdeDirsVar.isEmpty()) if (!kdeDirsVar.isEmpty())
kdeDirs += kdeDirsVar.split(u':', Qt::SkipEmptyParts); kdeDirs += kdeDirsVar.split(u':', Qt::SkipEmptyParts);

View File

@ -360,7 +360,7 @@ void QPlatformFontDatabase::releaseHandle(void *handle)
*/ */
QString QPlatformFontDatabase::fontDir() const QString QPlatformFontDatabase::fontDir() const
{ {
QString fontpath = QString::fromLocal8Bit(qgetenv("QT_QPA_FONTDIR")); QString fontpath = qEnvironmentVariable("QT_QPA_FONTDIR");
if (fontpath.isEmpty()) if (fontpath.isEmpty())
fontpath = QLibraryInfo::path(QLibraryInfo::LibrariesPath) + "/fonts"_L1; fontpath = QLibraryInfo::path(QLibraryInfo::LibrariesPath) + "/fonts"_L1;

View File

@ -51,7 +51,7 @@ void QBasicPlatformVulkanInstance::loadVulkanLibrary(const QString &defaultLibra
// embedded systems without a Vulkan loader and possibly with custom vendor // embedded systems without a Vulkan loader and possibly with custom vendor
// library names. // library names.
if (qEnvironmentVariableIsSet("QT_VULKAN_LIB")) 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 // Then what the platform specified. On Linux the version is likely 1, thus
// preferring libvulkan.so.1 over libvulkan.so. // preferring libvulkan.so.1 over libvulkan.so.

View File

@ -22,7 +22,7 @@ QEvdevKeyboardManager::QEvdevKeyboardManager(const QString &key, const QString &
Q_UNUSED(key); Q_UNUSED(key);
QString spec = QString::fromLocal8Bit(qgetenv("QT_QPA_EVDEV_KEYBOARD_PARAMETERS")); QString spec = qEnvironmentVariable("QT_QPA_EVDEV_KEYBOARD_PARAMETERS");
if (spec.isEmpty()) if (spec.isEmpty())
spec = specification; spec = specification;

View File

@ -24,7 +24,7 @@ QEvdevMouseManager::QEvdevMouseManager(const QString &key, const QString &specif
{ {
Q_UNUSED(key); Q_UNUSED(key);
QString spec = QString::fromLocal8Bit(qgetenv("QT_QPA_EVDEV_MOUSE_PARAMETERS")); QString spec = qEnvironmentVariable("QT_QPA_EVDEV_MOUSE_PARAMETERS");
if (spec.isEmpty()) if (spec.isEmpty())
spec = specification; spec = specification;

View File

@ -23,7 +23,7 @@ QEvdevTabletManager::QEvdevTabletManager(const QString &key, const QString &spec
if (qEnvironmentVariableIsSet("QT_QPA_EVDEV_DEBUG")) if (qEnvironmentVariableIsSet("QT_QPA_EVDEV_DEBUG"))
const_cast<QLoggingCategory &>(qLcEvdevTablet()).setEnabled(QtDebugMsg, true); 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()) if (spec.isEmpty())
spec = specification; spec = specification;

View File

@ -23,7 +23,7 @@ QEvdevTouchManager::QEvdevTouchManager(const QString &key, const QString &specif
if (qEnvironmentVariableIsSet("QT_QPA_EVDEV_DEBUG")) if (qEnvironmentVariableIsSet("QT_QPA_EVDEV_DEBUG"))
const_cast<QLoggingCategory &>(qLcEvdevTouch()).setEnabled(QtDebugMsg, true); 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()) if (spec.isEmpty())
spec = specification; spec = specification;

View File

@ -52,19 +52,19 @@ void QOutputMapping::set(QOutputMapping *mapping)
bool QDefaultOutputMapping::load() bool QDefaultOutputMapping::load()
{ {
static QByteArray configFile = qgetenv("QT_QPA_EGLFS_KMS_CONFIG"); static QString configFile = qEnvironmentVariable("QT_QPA_EGLFS_KMS_CONFIG");
if (configFile.isEmpty()) if (configFile.isEmpty())
return false; return false;
QFile file(QString::fromUtf8(configFile)); QFile file(configFile);
if (!file.open(QFile::ReadOnly)) { 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; return false;
} }
const QJsonDocument doc = QJsonDocument::fromJson(file.readAll()); const QJsonDocument doc = QJsonDocument::fromJson(file.readAll());
if (!doc.isObject()) { 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; return false;
} }

View File

@ -731,11 +731,9 @@ QString QIBusPlatformInputContextPrivate::getSocketPath()
QByteArray displayNumber = "0"; QByteArray displayNumber = "0";
bool isWayland = false; bool isWayland = false;
if (qEnvironmentVariableIsSet("IBUS_ADDRESS_FILE")) { if (QString path = qEnvironmentVariable("IBUS_ADDRESS_FILE"); !path.isNull()) {
QByteArray path = qgetenv("IBUS_ADDRESS_FILE"); return path;
return QString::fromLocal8Bit(path); } else if (display = qgetenv("WAYLAND_DISPLAY"); !display.isEmpty()) {
} else if (qEnvironmentVariableIsSet("WAYLAND_DISPLAY")) {
display = qgetenv("WAYLAND_DISPLAY");
isWayland = true; isWayland = true;
} else { } else {
display = qgetenv("DISPLAY"); display = qgetenv("DISPLAY");

View File

@ -50,29 +50,25 @@ DeviceIntegration::DeviceIntegration()
} }
} }
QByteArray requested;
// The environment variable can override everything. // The environment variable can override everything.
if (qEnvironmentVariableIsSet("QT_QPA_EGLFS_INTEGRATION")) { QString requested = qEnvironmentVariable("QT_QPA_EGLFS_INTEGRATION");
requested = qgetenv("QT_QPA_EGLFS_INTEGRATION"); if (requested.isNull()) {
} else {
// Device-specific makespecs may define a preferred plugin. // Device-specific makespecs may define a preferred plugin.
#ifdef EGLFS_PREFERRED_PLUGIN #ifdef EGLFS_PREFERRED_PLUGIN
#define DEFAULT_PLUGIN EGLFS_PREFERRED_PLUGIN #define DEFAULT_PLUGIN EGLFS_PREFERRED_PLUGIN
#define STR(s) #s #define STR(s) #s
#define STRQ(s) STR(s) #define STRQ(s) STR(s)
requested = STRQ(DEFAULT_PLUGIN); requested = QStringLiteral(STRQ(DEFAULT_PLUGIN));
#endif #endif
} }
// Treat "none" as special. There has to be a way to indicate // Treat "none" as special. There has to be a way to indicate
// that plugins must be ignored when the device is known to be // that plugins must be ignored when the device is known to be
// functional with the default, non-specialized integration. // functional with the default, non-specialized integration.
if (requested != QByteArrayLiteral("none")) { if (requested != QStringLiteral("none")) {
if (!requested.isEmpty()) { if (!requested.isEmpty()) {
QString reqStr = QString::fromLocal8Bit(requested); pluginKeys.removeOne(requested);
pluginKeys.removeOne(reqStr); pluginKeys.prepend(requested);
pluginKeys.prepend(reqStr);
} }
qCDebug(qLcEglDevDebug) << "EGL device integration plugin keys (sorted):" << pluginKeys; qCDebug(qLcEglDevDebug) << "EGL device integration plugin keys (sorted):" << pluginKeys;
while (!m_integration && !pluginKeys.isEmpty()) { while (!m_integration && !pluginKeys.isEmpty()) {

View File

@ -531,7 +531,7 @@ QByteArray QXcbIntegration::wmClass() const
if (m_instanceName) if (m_instanceName)
name = QString::fromLocal8Bit(m_instanceName); name = QString::fromLocal8Bit(m_instanceName);
if (name.isEmpty() && qEnvironmentVariableIsSet(resourceNameVar)) if (name.isEmpty() && qEnvironmentVariableIsSet(resourceNameVar))
name = QString::fromLocal8Bit(qgetenv(resourceNameVar)); name = qEnvironmentVariable(resourceNameVar);
if (name.isEmpty()) if (name.isEmpty())
name = argv0BaseName(); name = argv0BaseName();

View File

@ -54,7 +54,7 @@ QPlatformPrinterSupport *QPlatformPrinterSupportPlugin::get()
const QMultiMap<int, QString> keyMap = loader()->keyMap(); const QMultiMap<int, QString> keyMap = loader()->keyMap();
QMultiMap<int, QString>::const_iterator it = keyMap.cbegin(); QMultiMap<int, QString>::const_iterator it = keyMap.cbegin();
if (!qEnvironmentVariableIsEmpty("QT_PRINTER_MODULE")) { 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; }); QMultiMap<int, QString>::const_iterator it2 = std::find_if(keyMap.cbegin(), keyMap.cend(), [module](const QString &value){ return value == module; });
if (it2 == keyMap.cend()) if (it2 == keyMap.cend())
qWarning() << "Unable to load printer plugin" << module; qWarning() << "Unable to load printer plugin" << module;

View File

@ -187,7 +187,7 @@ int runUic(int argc, char *argv[])
if (parser.isSet(pythonPathOption)) if (parser.isSet(pythonPathOption))
pythonPaths = parser.value(pythonPathOption); pythonPaths = parser.value(pythonPathOption);
else if (qEnvironmentVariableIsSet(pythonPathVar)) else if (qEnvironmentVariableIsSet(pythonPathVar))
pythonPaths = QString::fromUtf8(qgetenv(pythonPathVar)); pythonPaths = qEnvironmentVariable(pythonPathVar);
driver.option().pythonRoot = pythonRoot(pythonPaths, inputFile); driver.option().pythonRoot = pythonRoot(pythonPaths, inputFile);
} }

View File

@ -3995,11 +3995,11 @@ QString QFileDialogPrivate::getEnvironmentVariable(const QString &string)
{ {
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX
if (string.size() > 1 && string.startsWith(u'$')) { 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 #else
if (string.size() > 2 && string.startsWith(u'%') && string.endsWith(u'%')) { 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 #endif
return string; return string;

View File

@ -363,8 +363,8 @@ QWidget *qt_desktopWidget = nullptr; // root window widgets
*/ */
void QApplicationPrivate::process_cmdline() void QApplicationPrivate::process_cmdline()
{ {
if (styleOverride.isEmpty() && qEnvironmentVariableIsSet("QT_STYLE_OVERRIDE")) if (styleOverride.isEmpty())
styleOverride = QString::fromLocal8Bit(qgetenv("QT_STYLE_OVERRIDE")); styleOverride = qEnvironmentVariable("QT_STYLE_OVERRIDE");
// process platform-indep command line // process platform-indep command line
if (qt_is_tty_app || !argc) if (qt_is_tty_app || !argc)
@ -1404,8 +1404,8 @@ QString QApplicationPrivate::desktopStyleKey()
{ {
#if defined(QT_BUILD_INTERNAL) #if defined(QT_BUILD_INTERNAL)
// Allow auto-tests to override the desktop style // Allow auto-tests to override the desktop style
if (qEnvironmentVariableIsSet("QT_DESKTOP_STYLE_KEY")) if (QString env = qEnvironmentVariable("QT_DESKTOP_STYLE_KEY"); !env.isNull())
return QString::fromLocal8Bit(qgetenv("QT_DESKTOP_STYLE_KEY")); return env;
#endif #endif
// The platform theme might return a style that is not available, find // The platform theme might return a style that is not available, find