Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a relative path for Qt dlls when releasing a Qt project?

When I release my Qt project, I want to redistribute the QtCore4.dll and QtGui4.dll files with my project, but not in the same directory as my .exe (in some other relative path).

How can I make my .exe find them automatically?

I also don't want to set the %PATH% or any other environment variable in my customer's environment.

like image 363
Igor Avatar asked Dec 07 '11 14:12

Igor


2 Answers

Probably the safest way is to launch your application using a script that does change the PATH (but only for that session) before launching your application. Here is a script I use to launch a custom version of Qt Creator:

set PATH=%PATH%;C:\Qt\qt474_custom_msvc2008_x64\lib;C:\Qt\jom
start C:\Qt\qtcreator231__custom_msvc2008_x64\bin\qtcreator.exe

I think there are alternatives, like SetDllDirectory, but (just like rpath on *nix), they introduce other problems. Either side-by-side dlls or a change in the PATH seems to be the most stable solution.

Also, did you mean that you want to deploy the debug versions (QtCore*d*4.dll, etc.) of those dlls? That would be pretty unusual--make sure you use the release versions. (Unless, of course, you have a valid reason for using the debug versions.)

like image 104
Dave Mateer Avatar answered Oct 06 '22 09:10

Dave Mateer


First, you should reconsider not changing the PATH in your customer's environment: many projects/applications do that, so you should consider that as a real option.

Second, the best way of doing this seems to be by editing a qt.conf file placed in the same folder as your executable. See this link for more information about editing an qt.conf file.

like image 26
Momergil Avatar answered Oct 06 '22 09:10

Momergil