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

Calling QCoreApplication::libraryPaths Before Constructing QApplication Causes Platform Plugins to Fail to Load

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Done
    • Affects Version/s: 4.8.x, 5.1.1, 5.2.0, 5.4.0, 5.5.0 Alpha
    • Fix Version/s: 5.6.0 RC
    • Component/s: Core: Plugins
    • Environment:
      Windows 7, but I don't think it's limited to that platform.
    • Commits:
      d96c29a5d14d142e81e5a2fd1b838a85a0fca187 ee0fd8700724848e73c228d973bf72e246077d07

      Description

      If QCoreApplication::libraryPaths() is called before constructing QApplication, Qt will fail to find the appropriate platform dll in the platforms subdirectory within the application path. This is because libraryPaths() doesn't initialize with the application path if called before QApplication is constructed. While there's a call to appendApplicationPathToLibraryPaths() in QCoreApplication::init() to attempt to remedy this, it's called a few lines too late, as the platform plugins are searched for a few lines above, in QGuiApplicationPrivate::createEventDispatcher().

      What makes this bug particularly sneaky is that several places call libraryPaths() internally, so it's not exactly obvious why all of a sudden the platform plugins are not being found. For example, this bug was manifesting for me because I was calling QApplication::setStyle before constructing QApplication (as recommended by the documentation), and the style happened to be unavailable on my platform, so QStyleFactory attempted to use QFactoryLoader to find an appropriate style dll on disk; QFactoryLoader called libraryPaths and made this bug happen. Also sneaky is that this bug will only manifest once the application is deployed: since the installed Qt directory remains in the libraryPaths, this will not be an issue on the development machine.

      Maybe the fix is to move initialization of libraryPaths (and the call to appendApplicationPathToLibraryPaths()) in QCoreApplication::init() to before the call to createEventDispatcher()?

      Discovery thread: https://qt-project.org/forums/viewthread/41594

        Attachments

          Issue Links

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

            Activity

              People

              • Assignee:
                ulherman Ulf Hermann
                Reporter:
                bkewl Bryan Cool
              • Votes:
                4 Vote for this issue
                Watchers:
                17 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: