Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. How to make my Qt application load dlls in a different folder?
QtWS25 Last Chance

How to make my Qt application load dlls in a different folder?

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
13 Posts 2 Posters 1.7k 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.
  • R Offline
    R Offline
    Roberrt
    wrote on 10 Nov 2022, 11:49 last edited by Roberrt 11 Oct 2022, 12:27
    #1

    How to set my qt project to search for the dependent DLLs in a different folder than the exe folder?

    I can't compile it as static because I'm using the QWebEngine module which didn't support being built statically.

    These are some things I already tried:

    Creating a qt.conf file in the same folder of the exe and specifying a path.

    [Paths]
    Prefix = D:/Project/New folder
    

    SetDllDirectory, addLibraryPath

        //SetDllDirectory(L"D:/Project/New folder"); 
    
        //QList<QString> list = {"D:/Project/New folder"};
        //QCoreApplication::setLibraryPaths(list);
    
        QCoreApplication::addLibraryPath("D:/Project/New folder");
    
        QApplication a(argc, argv);
    

    I was not sure when to call these 3 options, I tried calling then before the QApplication line.

    I have been able to deploy it using windeployqt, the project is being built using Qt 6.4 and Visual Studio 2019.

    J 1 Reply Last reply 10 Nov 2022, 12:22
    1
    • R Roberrt
      10 Nov 2022, 11:49

      How to set my qt project to search for the dependent DLLs in a different folder than the exe folder?

      I can't compile it as static because I'm using the QWebEngine module which didn't support being built statically.

      These are some things I already tried:

      Creating a qt.conf file in the same folder of the exe and specifying a path.

      [Paths]
      Prefix = D:/Project/New folder
      

      SetDllDirectory, addLibraryPath

          //SetDllDirectory(L"D:/Project/New folder"); 
      
          //QList<QString> list = {"D:/Project/New folder"};
          //QCoreApplication::setLibraryPaths(list);
      
          QCoreApplication::addLibraryPath("D:/Project/New folder");
      
          QApplication a(argc, argv);
      

      I was not sure when to call these 3 options, I tried calling then before the QApplication line.

      I have been able to deploy it using windeployqt, the project is being built using Qt 6.4 and Visual Studio 2019.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 10 Nov 2022, 12:22 last edited by
      #2

      @Roberrt On Windows you need to add the folder containing your libraries to environment variable PATH before starting your app.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      R 1 Reply Last reply 10 Nov 2022, 12:32
      0
      • J jsulm
        10 Nov 2022, 12:22

        @Roberrt On Windows you need to add the folder containing your libraries to environment variable PATH before starting your app.

        R Offline
        R Offline
        Roberrt
        wrote on 10 Nov 2022, 12:32 last edited by Roberrt 11 Oct 2022, 12:46
        #3

        @jsulm

        I have put all dependencies in the folder D:\New folder and added it under the user Environment Variables, is it correctly?

        I tested it, but it still complains about missing DLLs.

        J 1 Reply Last reply 10 Nov 2022, 12:33
        0
        • R Roberrt
          10 Nov 2022, 12:32

          @jsulm

          I have put all dependencies in the folder D:\New folder and added it under the user Environment Variables, is it correctly?

          I tested it, but it still complains about missing DLLs.

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 10 Nov 2022, 12:33 last edited by
          #4

          @Roberrt I was talking about PATH variable. I can't see it in your screen shot. And keep in mind: if you do it this way you will need to log off and on again.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          R 1 Reply Last reply 10 Nov 2022, 12:46
          0
          • J jsulm
            10 Nov 2022, 12:33

            @Roberrt I was talking about PATH variable. I can't see it in your screen shot. And keep in mind: if you do it this way you will need to log off and on again.

            R Offline
            R Offline
            Roberrt
            wrote on 10 Nov 2022, 12:46 last edited by Roberrt 11 Oct 2022, 12:49
            #5

            @jsulm said in How to make my Qt application load dlls in a different folder?:

            PATH variable

            To clarify, are you referring to System Variables > Path variables?

            I've added the folder and rebooted, but now I'm getting this error:

            This application failed to start because no Qt platform plugin could be initialized.
            

            This is my dependencies folder:

            90824fec-ec3a-4387-bb5b-59418764c19d-image.png

            J 1 Reply Last reply 10 Nov 2022, 12:57
            0
            • R Roberrt
              10 Nov 2022, 12:46

              @jsulm said in How to make my Qt application load dlls in a different folder?:

              PATH variable

              To clarify, are you referring to System Variables > Path variables?

              I've added the folder and rebooted, but now I'm getting this error:

              This application failed to start because no Qt platform plugin could be initialized.
              

              This is my dependencies folder:

              90824fec-ec3a-4387-bb5b-59418764c19d-image.png

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 10 Nov 2022, 12:57 last edited by
              #6

              @Roberrt said in How to make my Qt application load dlls in a different folder?:

              are you referring to System Variables > Path variables?

              I'm referring to PATH environment variable.
              You can set it in System Variables > Path variables. But as I already pointed out above: you need to log off and log in again after changing PATH. If it then still does not work then open a terminal and enter command "set" - check the value of the PATH variable there.
              You should also consider that using paths with spaces can easily cause problems.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              R 1 Reply Last reply 10 Nov 2022, 13:31
              0
              • J jsulm
                10 Nov 2022, 12:57

                @Roberrt said in How to make my Qt application load dlls in a different folder?:

                are you referring to System Variables > Path variables?

                I'm referring to PATH environment variable.
                You can set it in System Variables > Path variables. But as I already pointed out above: you need to log off and log in again after changing PATH. If it then still does not work then open a terminal and enter command "set" - check the value of the PATH variable there.
                You should also consider that using paths with spaces can easily cause problems.

                R Offline
                R Offline
                Roberrt
                wrote on 10 Nov 2022, 13:31 last edited by
                #7

                @jsulm said in How to make my Qt application load dlls in a different folder?:

                You should also consider that using paths with spaces can easily cause problems.

                I modified it to a path without spaces, and rebooted, continue getting the same error message.

                If i execute the exe inside of the DLL folder it works correctly.

                I think the problem is these folders dont?

                I used windeployqt to copy the dependencies, is it possible to 'copy' everything without creating any folder?

                J 1 Reply Last reply 10 Nov 2022, 13:47
                0
                • R Roberrt
                  10 Nov 2022, 13:31

                  @jsulm said in How to make my Qt application load dlls in a different folder?:

                  You should also consider that using paths with spaces can easily cause problems.

                  I modified it to a path without spaces, and rebooted, continue getting the same error message.

                  If i execute the exe inside of the DLL folder it works correctly.

                  I think the problem is these folders dont?

                  I used windeployqt to copy the dependencies, is it possible to 'copy' everything without creating any folder?

                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 10 Nov 2022, 13:47 last edited by
                  #8

                  @Roberrt What about my suggestion from above: "If it then still does not work then open a terminal and enter command "set" - check the value of the PATH variable there.". If the PATH is set correctly try to start your app from a terminal - does that work?

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  1
                  • R Offline
                    R Offline
                    Roberrt
                    wrote on 10 Nov 2022, 14:28 last edited by
                    #9

                    @jsulm yes, when i enter "set" in the terminal i can see the path.

                    I tried launching the app using the terminal it gave the same error.

                    J 1 Reply Last reply 10 Nov 2022, 14:29
                    0
                    • R Roberrt
                      10 Nov 2022, 14:28

                      @jsulm yes, when i enter "set" in the terminal i can see the path.

                      I tried launching the app using the terminal it gave the same error.

                      J Offline
                      J Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on 10 Nov 2022, 14:29 last edited by
                      #10

                      @Roberrt Can you show your PATH?

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      R 1 Reply Last reply 10 Nov 2022, 14:36
                      0
                      • J jsulm
                        10 Nov 2022, 14:29

                        @Roberrt Can you show your PATH?

                        R Offline
                        R Offline
                        Roberrt
                        wrote on 10 Nov 2022, 14:36 last edited by Roberrt 11 Oct 2022, 14:36
                        #11

                        @jsulm

                        20f7b666-e9e4-459f-837f-c4cfdd4b2ce6-image.png

                        J 1 Reply Last reply 10 Nov 2022, 14:42
                        0
                        • R Roberrt
                          10 Nov 2022, 14:36

                          @jsulm

                          20f7b666-e9e4-459f-837f-c4cfdd4b2ce6-image.png

                          J Offline
                          J Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on 10 Nov 2022, 14:42 last edited by
                          #12

                          @Roberrt If c:\Users\Public\Qt is the folder with your libs it should work.
                          You also tried to use qt.conf: did you specify the folder with the libs using "Libraries = PAT_TO_LIBS_FOLDER"? Prefix is the app folder.

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          R 1 Reply Last reply 10 Nov 2022, 19:48
                          1
                          • J jsulm
                            10 Nov 2022, 14:42

                            @Roberrt If c:\Users\Public\Qt is the folder with your libs it should work.
                            You also tried to use qt.conf: did you specify the folder with the libs using "Libraries = PAT_TO_LIBS_FOLDER"? Prefix is the app folder.

                            R Offline
                            R Offline
                            Roberrt
                            wrote on 10 Nov 2022, 19:48 last edited by Roberrt 11 Oct 2022, 20:40
                            #13

                            @jsulm
                            I got it working for a new project containing just a push button, I also needed to create a variable with the name QT_PLUGIN_PATH under the System variables environment, and set the folder which contains these plugins folders (platforms, etc), in my case C:\Users\Public\Qt.

                            But for my app using qwebengine its not working, when i run the exe i don't see any error message neither my gui, then it closes :(

                            1 Reply Last reply
                            0

                            5/13

                            10 Nov 2022, 12:46

                            topic:navigator.unread, 8
                            • Login

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