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. QCoreApplication::setLibraryPaths from CMake
Qt 6.11 is out! See what's new in the release blog

QCoreApplication::setLibraryPaths from CMake

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 4 Posters 2.8k Views 2 Watching
  • 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 Offline
    C Offline
    ChrisTof
    wrote on last edited by
    #3

    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);
    
    JKSHJ 1 Reply Last reply
    0
    • C ChrisTof

      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);
      
      JKSHJ Online
      JKSHJ Online
      JKSH
      Moderators
      wrote on last edited by JKSH
      #4

      @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
      1
      • JKSHJ 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.

        C Offline
        C Offline
        ChrisTof
        wrote on last edited by
        #5

        @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.

        JKSHJ 1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #6

          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
          0
          • C ChrisTof

            @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.

            JKSHJ Online
            JKSHJ Online
            JKSH
            Moderators
            wrote on last edited by JKSH
            #7

            @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
            0
            • SGaistS SGaist

              Hi,

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

              C Offline
              C Offline
              ChrisTof
              wrote on last edited by
              #8

              @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
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #9

                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
                0
                • C Offline
                  C Offline
                  ChrisTof
                  wrote on last edited by
                  #10

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

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #11

                    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
                    0
                    • C Offline
                      C Offline
                      ChrisTof
                      wrote on last edited by
                      #12

                      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
                      0

                      • Login

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