Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-24541

QtCore doesn't read qt.conf stored in application's bundle resource

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3: Somewhat important
    • 5.5.0 Alpha
    • 4.8.0
    • Core: Other
    • None
    • mac 10.6
    • macOS
    • 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

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              ulherman Ulf Hermann
              jyavenard Jean-Yves Avenard
              Veli-Pekka Heinonen Veli-Pekka Heinonen
              Votes:
              1 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes