Details
-
Bug
-
Resolution: Fixed
-
P3: Somewhat important
-
4.8.0
-
None
-
mac 10.6
-
-
1fc6056ff5526e61419262931de79137bf7c1b4d
Description
I have an application I'm trying to package for mac. Previously we were compiling Qt statically, so this issue was never raised before
I couldn't find a reason why the sqldrivers plugins weren't loaded, despite having a qt.conf stored in the application bundle resources.
In src/corelib/global/qlibraryinfo.cpp, in QLibrarySettings::QLibrarySettings()
The mac specific code is only triggered following the test
if (!QFile::exists(qtconfig) && QCoreApplication::instance())
At that stage in the application runtime, QCoreApplication::instance() always return null (it hasn't been created yet), so it doesn't even try to look for the qt.conf stored in the bundle.
As such, the application's qt.conf is always ignored.
The code should be changed as follow:
QSettings *QLibraryInfoPrivate::findConfiguration() { QString qtconfig = QLatin1String(":/qt/etc/qt.conf"); #ifdef BOOTSTRAPPING if(!QFile::exists(qtconfig)) qtconfig = qmake_libraryInfoFile(); #else #ifdef Q_OS_MAC if (!QFile::exists(qtconfig)) { CFBundleRef bundleRef = CFBundleGetMainBundle(); if (bundleRef) { QCFType<CFURLRef> urlRef = CFBundleCopyResourceURL(bundleRef, QCFString(QLatin1String("qt.conf")), 0, 0); if (urlRef) { QCFString path = CFURLCopyFileSystemPath(urlRef, kCFURLPOSIXPathStyle); qtconfig = QDir::cleanPath(path); } } if (qtconfig.isEmpty() && QCoreApplication::instance()) { #else if (!QFile::exists(qtconfig) && QCoreApplication::instance()) { #endif QDir pwd(QCoreApplication::applicationDirPath()); qtconfig = pwd.filePath(QLatin1String("qt.conf")); } } #endif if (QFile::exists(qtconfig)) return new QSettings(qtconfig, QSettings::IniFormat); return 0; //no luck }
Additionally, I believe the system-wide qt.conf should always be ignored if the application bundle contains a qt.conf.
Currently, if the file :/qt/etc/qt.conf exists, the custom qt.conf in the application bundle is ignored and the system-wide is used.
To do so, the function would then become:
QSettings *QLibraryInfoPrivate::findConfiguration() { QString qtconfig = QLatin1String(":/qt/etc/qt.conf"); #ifdef BOOTSTRAPPING if(!QFile::exists(qtconfig)) qtconfig = qmake_libraryInfoFile(); #else #ifdef Q_OS_MAC CFBundleRef bundleRef = CFBundleGetMainBundle(); if (bundleRef) { QCFType<CFURLRef> urlRef = CFBundleCopyResourceURL(bundleRef, QCFString(QLatin1String("qt.conf")), 0, 0); if (urlRef) { QCFString path = CFURLCopyFileSystemPath(urlRef, kCFURLPOSIXPathStyle); qtconfig = QDir::cleanPath(path); } } if ((qtconfig.isEmpty() || !QFile::exists(qtconfig)) && QCoreApplication::instance()) { #else if (!QFile::exists(qtconfig) && QCoreApplication::instance()) { #endif QDir pwd(QCoreApplication::applicationDirPath()); qtconfig = pwd.filePath(QLatin1String("qt.conf")); } #endif if (QFile::exists(qtconfig)) return new QSettings(qtconfig, QSettings::IniFormat); return 0; //no luck }
Attachments
Issue Links
- relates to
-
QTBUG-38598 Calling QCoreApplication::libraryPaths Before Constructing QApplication Causes Platform Plugins to Fail to Load
- Closed