Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QT5: Catch 22 regarding applicationDirPath and setLibraryPaths
QtWS25 Last Chance

QT5: Catch 22 regarding applicationDirPath and setLibraryPaths

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 3.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KevinKnowles
    wrote on last edited by
    #1

    I've been working on upgrading our app to QT5, and ran into an issue regarding the new platform libraries that are loaded on boot.

    As far as I can tell, the platform plugin is scanned for and loaded as soon as the QGuiApplication object is first created. As we ship QT and all its plugins alongside our executable, we need to be able to show QT where the plugin will be by first calling QCoreApplication::setLibraryPaths.

    Here's where it gets tricky. QCoreApplication doesn't allow you to call applicationDirPath before you instantiate your first QCoreApplication instance, meaning we can't find the location to pass to setLibraryPaths. Sure, we could use a relative path for the call, but our app has no guarantees of working directory.

    At the moment, I am replicating the logic of applicationDirPath in my own code, but this can't be the best solution. Is there any way to access the application path prior to loading the platform DLL?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      KevinKnowles
      wrote on last edited by
      #2

      After fighting with this for hours (QCoreApplication and QGuiApplication don't seem to have ANY public members I could override and hook into), I came up with a really hacky solution that seems to work perfectly well.

      As QCoreApplication doesn't rely on the platform library, and cleans up its singleton after it's deleted, this code seems to work:

      @
      QString appDir;
      {
      QCoreApplication temp(argc, argv);
      appDir = QCoreApplication::applicationDirPath();
      }

      // ~~ Set up library paths here using appDir as the root

      QApplication myRealApplication(argc,argv);

      // ...
      @

      I'm sure there's a little bit of overhead from creating two seperate application instances, but it saves a HUGE headache. Finding the application directory without applicationDirPath is not fun.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tobias.hunger
        wrote on last edited by
        #3

        Have you considered to "file a bug report":http://bugreports.qt-project.org/ about this so that it is not missed?

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on last edited by
          #4

          You should be able to use QT_QPA_PLATFORM_PLUGIN_PATH and QT_QPA_PLATFORM environment variables as well if this is of use for you.

          You won't be able to get the executable path without instantiating an object, as argv is required to determine the path on some platforms. But you can ship a qt.conf along with your application which explicitly sets a path for QLibraryInfo::PluginsPath.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved