Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved QCoreApplication::setLibraryPaths from CMake

    General and Desktop
    4
    12
    648
    Loading More Posts
    • 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.
    • C
      ChrisTof last edited by

      I can set LibraryPath from C++. How I can set LibraryPath from CMake by passing a variable?
      I work on Windows. There is no QT installed on a machine where I deploy. I provide all libs, but I do not want them to be in the same folder as .exe.

      1 Reply Last reply Reply Quote 0
      • Christian Ehrlicher
        Christian Ehrlicher Lifetime Qt Champion last edited by

        This is not possible - how should this work at all?

        https://forum.qt.io/topic/104721/windows-minimum-files-in-deployment-that-cannot-be-moved

        Qt has to stay free or it will die.

        1 Reply Last reply Reply Quote 2
        • C
          ChrisTof last edited by

          CMake:

          set(QT_PLUGIN_PATH "C:/Program Files/qtPluginsFolder")
          add_definitions( -DQT_PLUGIN_PATH=\"${QT_PLUGIN_PATH}\")
          

          C++:

          QStringList pluginsPaths;
          pluginsPaths << QT_PLUGIN_PATH; // QT_PLUGIN_PATH set in cmake.
          QCoreApplication::setLibraryPaths(pluginsPaths);
          
          JKSH 1 Reply Last reply Reply Quote 0
          • JKSH
            JKSH Moderators @ChrisTof last edited by JKSH

            @christof said in QCoreApplication::setLibraryPaths from CMake:

            CMake:

            set(QT_PLUGIN_PATH "C:/Program Files/qtPluginsFolder")
            add_definitions( -DQT_PLUGIN_PATH=\"${QT_PLUGIN_PATH}\")
            

            C++:

            QStringList pluginsPaths;
            pluginsPaths << QT_PLUGIN_PATH; // QT_PLUGIN_PATH set in cmake.
            QCoreApplication::setLibraryPaths(pluginsPaths);
            

            This sets the environment variable on the development PC, but the environment variable cannot be transferred to deployment PCs.

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            C 1 Reply Last reply Reply Quote 1
            • C
              ChrisTof @JKSH last edited by

              @jksh said in QCoreApplication::setLibraryPaths from CMake:
              Do you mean the cmake part? If I understand correctly, add_definitions does not set the environment variable, but
              Adds definitions to the compiler command line... what allows us to add preprocessor definitions.

              JKSH 1 Reply Last reply Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                Hi,

                Out of curiosity, why do you want to add that path ?
                Do you have any special requirements ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                C 1 Reply Last reply Reply Quote 0
                • JKSH
                  JKSH Moderators @ChrisTof last edited by JKSH

                  @christof said in QCoreApplication::setLibraryPaths from CMake:

                  @jksh said in QCoreApplication::setLibraryPaths from CMake:
                  Do you mean the cmake part? If I understand correctly, add_definitions does not set the environment variable, but
                  Adds definitions to the compiler command line... what allows us to add preprocessor definitions.

                  You're right; sorry for the noise!

                  I'd still recommend picking a different name for the preprocessor definition, to make it clear that it's not the QT_PLUGIN_PATH environment variable that Qt expects.

                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                  1 Reply Last reply Reply Quote 0
                  • C
                    ChrisTof @SGaist last edited by

                    @sgaist
                    There is an application that comprises of modules. One of the modules (which we talk about here) uses Qt. I have to deliver library with required qt files and I have to place them in a separate folder than .exe.

                    @JKSH
                    Right, might be confusing, thank you for your suggestion.

                    1 Reply Last reply Reply Quote 0
                    • SGaist
                      SGaist Lifetime Qt Champion last edited by

                      Is that folder relative to the executable file ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply Reply Quote 0
                      • C
                        ChrisTof last edited by

                        The folder location may change in future therefore I do not want to provide a relative path.

                        1 Reply Last reply Reply Quote 0
                        • SGaist
                          SGaist Lifetime Qt Champion last edited by

                          The problem you will get with using absolute paths is that your users may very well not install your application in the same disk, nor the same folder that you hardcoded.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply Reply Quote 0
                          • C
                            ChrisTof last edited by

                            Another solution is to set the environment variable during the software installation. Using Wix:

                            <CPackWiXPatch>
                                <CPackWiXFragment Id="CM_DP_lib">
                                    <Component Id="EnvQml2ImportPath" Guid="****">
                                        <CreateFolder />
                                        <Environment Action="set" Id="Qml2ImportPathEnv" Name="QML2_IMPORT_PATH" Part="last" Permanent="no" Separator=";" System="yes" Value="[INSTALL_ROOT]qt"/>
                                    </Component>
                                </CPackWiXFragment>
                                <CPackWiXFragment Id="#PRODUCTFEATURE">
                                    <ComponentRef Id="EnvQml2ImportPath" />
                                </CPackWiXFragment>
                            </CPackWiXPatch>
                            

                            Then, use this enviroment variable in the cpp:

                                QStringList pluginsPaths;
                                pluginsPaths << std::getenv("QML2_IMPORT_PATH");
                                QCoreApplication::setLibraryPaths(pluginsPaths);
                            
                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post