Load plugins from PATH variable



  • It seems not possible to load plugins like platform/qwindows.dll from system location. I tried copying contents of plugins directory in somewhere in C:/qt5/plugins an add that location to system PATH. Unfortunately application won't run. It just refuses to link against (better say dynamically load) plugins.

    I would my Qt application to load plugins from one of system paths instead of those hard-coded in Qt5Core.dll


  • Moderators

    You can use QCoreApplication::setLibraryPaths() to setup some additional paths for your app to look in for plugins.
    Please remember though not to put any of the Qt libs in the system paths like windows, system32 etc. Those are reserved for system and you should not temper with them. Also it makes hard to use different versions of Qt libs by different apps.
    IMHO the best approach is to deploy Qt along in your app directory, as it's clean and easy to modify/find/remove.



  • [quote author="Krzysztof Kawa" date="1357424053"]You can use QCoreApplication::setLibraryPaths() to setup some additional paths for your app to look in for plugins.
    Please remember though not to put any of the Qt libs in the system paths like windows, system32 etc. Those are reserved for system and you should not temper with them. Also it makes hard to use different versions of Qt libs by different apps.
    IMHO the best approach is to deploy Qt along in your app directory, as it's clean and easy to modify/find/remove.[/quote]

    Applications won't run until qplatform.dll is not loaded. So before calling QCoreApplication::setLibraryPaths() I'm getting the error. Setting env variable QT_PLUGINS_PATH solved the issue.

    I can't see why system32 is considered a bad place to put libraries! Seems there is no some sort of standard filesystem hierarchy for libraries, executables, etc. Who cares about system reserved paths? I'm just happy with my Qt libs in system32 until I found some rational reason to avoid putting them there. Not just "reserved" !


  • Moderators

    Ok, let me try to give you some rational reasons:

    1. There is no clean way to uninstall your app. You never know if the dlls you put there did not overwrite something that other app used or if you've got several apps using the same dlls. Also your autoupdate may mess up other apps if they share libraries.

    2. You are very wrong about there not being standard hierarchy. It's just that many people ignorantly choose not to follow it, just like you do now, and then we end up with "My documents" filled with "not really my documents". There is a place for shared libraries in windows and it's in %Program Files%\CommonFiles<your company name>\ . This way you're responsible for shared libraries only within your products and if you mess something with versions it's only your products problem. Don't put stuff in system32 just "because it works". It might actually not work at all.

    3. Extension to 1. There's no telling which files belong to which app this way. It creates structural mess. Well behaved apps put their exec and libs in "Program Files", their shared libraries in "Common Files", variable app and user data in %AppData%. This way if your uninstaller goes haywire it's easy to remove it manually.

    4. A common scenario these days is Windows installed on a relatively small but fast SSD drive and all programs and personal data on a separate drive vie eg. moved "Libraries" in Windows 7/8. Don't you hate when you select an install path on a different partition and the app eats up a lot of space on your C: drive anyway? I know I do!

    5. When you use restore points in this configuration you might end up with broken installation and garbage leftovers.

    6. Somewhat less common bot quite realistic: on certain system configurations (often enterprise) user has limited admin rights and can install to "Program Files" but not to system directories.


  • Moderators

    I haven't actually tried it but I though plugins like qplatform.dll are loaded dynamically via LoadLibrary, so aren't actually required on startup like QtCore or QtGui. Thus I think if you'd call setLibraryPaths() before any usage (eg. as a first line in the main(), before you create any widgets) it would work.
    But again - I can be wrong.

    Setting QT_PLUGINS_PATH on users machine seems like a very fragile mechanism. What if you had two apps with different versions of Qt?



  • Ok it's better now.

    Currently my installer copies Qt/MinGW/ICU/... DLLs to corresponding subdirectories of /windows/system32 and adds those paths to PATH of system. Default path is windows/system32 but user can change the installation path. What you suggest instead? Is Common Files or Program Files good for libraries?

    I've never feel good in Windows. I hate that OS for some unknown reason. It looks to me somehow broken and insane in comparison with Linux :/ I think I'm going to ignore installers of Qt5 for windows. Just leave that part of project to somebody with much more Windows experience. I'm gonna distribute my lovely deb and rpms :)

    Thanks



  • [quote author="Krzysztof Kawa" date="1357496716"]I haven't actually tried it but I though plugins like qplatform.dll are loaded dynamically via LoadLibrary, so aren't actually required on startup like QtCore or QtGui. Thus I think if you'd call setLibraryPaths() before any usage (eg. as a first line in the main(), before you create any widgets) it would work.
    But again - I can be wrong.

    Setting QT_PLUGINS_PATH on users machine seems like a very fragile mechanism. What if you had two apps with different versions of Qt?[/quote]

    You're right. I was giving a wrong path to the function :P Erased QT_PUGINS_PATH and it works with setLibraryPaths.

    In my case users won't have different versions, but some relatively heavy programs sharing same versions of Qt.

    Let me tell you what I'm trying to achieve. I'm planning to reduce redundancy of those shared files that each program have a copy of. It's between 12 to 20 programs that each one has a 20 ~ 100 MB of DLLs (with Qt4). We need hard disk space to store analysis data from local machine and clustered nodes. There is 80 GB of space on each computer, 5 computer have Windows 7 installed, 25 computers have Windows XP. Disk space is critical. I'm planning to save about 1~5 GB for each computer.


  • Moderators

    [quote author="soroush" date="1357497036"]
    I've never feel good in Windows. I hate that OS for some unknown reason. It looks to me somehow broken and insane in comparison with Linux :/[/quote]
    Funny, I get the same feeling every time I have to start Ubuntu :) I guess those are just personal preferences.

    Edit: forum formatting :(

    The rule of thumb I'd say is to deploy any needed libraries along with your executable to
    @
    %PROGRAMFILES%<YourApp> // on 32bit system
    %PROGRAMFILES%<YourApp> or %PROGRAMFILES(X86)%<YourApp> //on 64 bit system, depending which your app is.
    @

    If you have more than one app that uses some libraries, so like a suite (like ms office or adobe creative suite) put those shared libs to
    @
    %COMMONPROGRAMFILES%<YourCompany> //on 32 bit system
    %COMMONPROGRAMFILES%<YourCompany> or %COMMONPROGRAMFILES(X86)%<YourCompany> //on 64bit system depending on which your app is.
    @



  • I will change default path of my installer from {sys} to %COMMONPROGRAMFILES%\EBO-Qt. And for convenience, mark the "Add EBO-Qt path to system PATH" task as not recommended. Or maybe completely remove that (should add all programs one line of code... )


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.