diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2018-07-04 15:23:18 +0200 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2018-07-16 09:39:26 +0000 |
commit | 62abe69e45a8958006b7b83cf1de6033be431eeb (patch) | |
tree | e7cf5e5a8ff619f018bc8848cdf807a3781ba6a9 /src/quickcontrols2 | |
parent | 5783cc354b85ba9a77378da34d911a0cfdb31b73 (diff) |
Fix qrc paths in QT_QUICK_CONTROLS_STYLE_PATH
Parse the environment variable manually when the platform's list separator
is ':', to avoid issues with qrc paths (which start with ':') not working.
Task-number: QTBUG-68219
Change-Id: Ic71d49da5a72a37bc1d2e7b19fbf1de71b3917f3
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/quickcontrols2')
-rw-r--r-- | src/quickcontrols2/qquickstyle.cpp | 62 |
1 files changed, 60 insertions, 2 deletions
diff --git a/src/quickcontrols2/qquickstyle.cpp b/src/quickcontrols2/qquickstyle.cpp index 804b53fd..73c604de 100644 --- a/src/quickcontrols2/qquickstyle.cpp +++ b/src/quickcontrols2/qquickstyle.cpp @@ -260,13 +260,71 @@ struct QQuickStyleSpec Q_GLOBAL_STATIC(QQuickStyleSpec, styleSpec) +static QStringList parseStylePathsWithColon(const QString &var) +{ + QStringList paths; + const QChar colon = QLatin1Char(':'); + int currentIndex = 0; + + do { + int nextColonIndex = -1; + QString path; + + if (var.at(currentIndex) == colon) { + // This is either a list separator, or a qrc path. + if (var.at(currentIndex + 1) == colon) { + // It's a double colon (list separator followed by qrc path); + // find the end of the path. + nextColonIndex = var.indexOf(colon, currentIndex + 2); + path = var.mid(currentIndex + 1, + nextColonIndex == -1 ? -1 : nextColonIndex - currentIndex - 1); + } else { + // It's a single colon. + nextColonIndex = var.indexOf(colon, currentIndex + 1); + if (currentIndex == 0) { + // If we're at the start of the string, then it's a qrc path. + path = var.mid(currentIndex, + nextColonIndex == -1 ? -1 : nextColonIndex - currentIndex); + } else { + // Otherwise, it's a separator. + path = var.mid(currentIndex + 1, + nextColonIndex == -1 ? -1 : nextColonIndex - currentIndex - 1); + } + } + } else { + // It's a file path. + nextColonIndex = var.indexOf(colon, currentIndex); + path = var.mid(currentIndex, + nextColonIndex == -1 ? -1 : nextColonIndex - currentIndex); + } + + paths += path; + currentIndex = nextColonIndex; + + // Keep going until we can't find any more colons, + // or we're at the last character. + } while (currentIndex != -1 && currentIndex < var.size() - 1); + + return paths; +} + QStringList QQuickStylePrivate::stylePaths() { // system/custom style paths QStringList paths; if (Q_UNLIKELY(!qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE_PATH"))) { - const QByteArray value = qgetenv("QT_QUICK_CONTROLS_STYLE_PATH"); - paths += QString::fromLocal8Bit(value).split(QDir::listSeparator(), QString::SkipEmptyParts); + const QString value = QString::fromLocal8Bit(qgetenv("QT_QUICK_CONTROLS_STYLE_PATH")); + const QChar listSeparator = QDir::listSeparator(); + if (listSeparator == QLatin1Char(':')) { + // Split manually to avoid breaking paths on systems where : is the list separator, + // since it's also used for qrc paths. + paths += parseStylePathsWithColon(value); + } else { + // Fast/simpler path for systems where something other than : is used as + // the list separator (such as ';'). + const QStringList customPaths = value.split(listSeparator, QString::SkipEmptyParts); + paths += customPaths; + } } // built-in import paths |