Fix relocated Qt to be found when its path has non-ASCII characters

The path returned by dladdr seems to be encoded with the current
locale encoding which means that if it contains unicode characters, the
fromLatin1() call mangles the path, and QFile::exists reports that
the path does not exist.

To preserve non-ASCII characters use fromLocal8Bit() instead.

This should fix the runtime issue of finding the Qt prefix when the
Qt library path has non-ASCII characters.

Amends 2f52afda8e.
Amends 4ac872639e.

Fixes: QTBUG-84272
Task-number: QTBUG-15234
Pick-to: 5.14 5.15
Change-Id: I37019ed219cf2cf7d9663cb1e16acdb97b3bdf09
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Alexandru Croitor 2020-05-18 14:26:39 +02:00
parent 941039356d
commit 19b6ae6637
1 changed files with 3 additions and 3 deletions

View File

@ -576,7 +576,7 @@ static QString getRelocatablePrefix()
Dl_info info;
int result = dladdr(reinterpret_cast<void *>(&QLibraryInfo::isDebugBuild), &info);
if (result > 0 && info.dli_fname)
prefixPath = prefixFromQtCoreLibraryHelper(QString::fromLatin1(info.dli_fname));
prefixPath = prefixFromQtCoreLibraryHelper(QString::fromLocal8Bit(info.dli_fname));
#elif defined(Q_OS_WIN)
HMODULE hModule = getWindowsModuleHandle();
const int kBufferSize = 4096;
@ -590,7 +590,7 @@ static QString getRelocatablePrefix()
// QtCore DLL is next to the executable. This is either a windeployqt'ed executable or an
// executable within the QT_HOST_BIN directory. We're detecting the latter case by checking
// whether there's an import library corresponding to our QtCore DLL in PREFIX/lib.
const QString libdir = QString::fromLatin1(
const QString libdir = QString::fromLocal8Bit(
qt_configure_strs + qt_configure_str_offsets[QLibraryInfo::LibrariesPath - 1]);
const QLatin1Char slash('/');
#if defined(Q_CC_MINGW)
@ -622,7 +622,7 @@ static QString getRelocatablePrefix()
// QTBUG-78948: libQt5Core.so may be located in subdirectories below libdir.
// See "Hardware capabilities" in the ld.so documentation and the Qt 5.3.0
// changelog regarding SSE2 support.
const QString libdir = QString::fromLatin1(
const QString libdir = QString::fromLocal8Bit(
qt_configure_strs + qt_configure_str_offsets[QLibraryInfo::LibrariesPath - 1]);
QDir prefixDir(prefixPath);
while (!prefixDir.exists(libdir)) {