diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2017-11-15 14:50:58 +0100 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2017-11-22 21:27:45 +0000 |
commit | eade2255ea7cd8200569080e9b295479b1f51bed (patch) | |
tree | 5f0c7012350cf4f89f31ab2584ceb7350edbae50 /src/corelib | |
parent | fb2e795c6e61b3c5fb699aefdb2662769c12f76b (diff) |
Windows: Resolve QStandardPaths config location without qApp instance
Calling QCoreApplication::applicationDirPath() requires an app instance,
but on Windows the implementation just relies on qAppFileName(), which
does not require any instance. As resolving the standard paths could
be needed before QCoreApplication instantiation, e.g. for categorized
logging, we use qAppFileName() directly.
Change-Id: Id882cebd528bcb8e945e73a83f1dc3d599b74d1d
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/io/qstandardpaths_win.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/corelib/io/qstandardpaths_win.cpp b/src/corelib/io/qstandardpaths_win.cpp index a64bde6fb4..a06b204da7 100644 --- a/src/corelib/io/qstandardpaths_win.cpp +++ b/src/corelib/io/qstandardpaths_win.cpp @@ -201,6 +201,10 @@ QString QStandardPaths::writableLocation(StandardLocation type) return result; } +#ifndef QT_BOOTSTRAPPED +extern QString qAppFileName(); +#endif + QStringList QStandardPaths::standardLocations(StandardLocation type) { QStringList dirs; @@ -217,8 +221,13 @@ QStringList QStandardPaths::standardLocations(StandardLocation type) dirs.append(programData); } #ifndef QT_BOOTSTRAPPED - dirs.append(QCoreApplication::applicationDirPath()); - dirs.append(QCoreApplication::applicationDirPath() + QLatin1String("/data")); + // Note: QCoreApplication::applicationDirPath(), while static, requires + // an application instance. But we might need to resolve the standard + // locations earlier than that, so we fall back to qAppFileName(). + QString applicationDirPath = qApp ? QCoreApplication::applicationDirPath() + : QFileInfo(qAppFileName()).path(); + dirs.append(applicationDirPath); + dirs.append(applicationDirPath + QLatin1String("/data")); #endif // !QT_BOOTSTRAPPED } // isConfigLocation() |