From eade2255ea7cd8200569080e9b295479b1f51bed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 15 Nov 2017 14:50:58 +0100 Subject: Windows: Resolve QStandardPaths config location without qApp instance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/corelib/io/qstandardpaths_win.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/corelib/io') 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() -- cgit v1.2.3