19

I am new to qmake and I am trying to build an existing application. Qt was originally installed in /usr/local/lib/Qt-4.3.5 and 'qmake -query QT_INSTALL_PREFIX' returns that path.

I have moved the Qt library to another location and the generated Makefiles are peppered with the /usr/local original path.

How can I force qmake to use the new location I selected without recompiling Qt?

David Segonds
  • 83,345
  • 10
  • 45
  • 66

3 Answers3

39

I was looking into this and found a way that works (in qt 4.7.2) by customizing qt with a qt.conf file.

In my case, I added a qt4-4.7.2/bin/qt.conf (It must be in the same place as the qmake executable)

With the following contents:

[Paths]
Prefix = c:/my_path/to/qt4-4.7.2

and the qmake -query started returning the proper paths!

See: http://doc.qt.io/qt-4.8/qt-conf.html for more details


[Update:] Since at least Qt 5.3.1 (tested with static versions of 5.3.1 and 5.5 on Windows 8) you can simply do

[Paths]
Prefix = ..

and deploy the Qt installation anywhere.

Tim Meyer
  • 12,210
  • 8
  • 64
  • 97
Fabio Zadrozny
  • 24,814
  • 4
  • 66
  • 78
  • It does work for me with 4.8.2. qt.conf has to be in the same directory as the exec'd qmake. You could create a temporary dir, make a sym link to /usr/bin/qmake (if that's where qmake is for you) there and add qt.conf in that directory. If you think it's not using your qt.conf, try using strace or similar to see which qt.conf qmake is trying to open. – Juan Nov 16 '12 at 02:30
  • I've been using Qt for years without knowing that!! It works and it's so cool. The link you provide is out-of-date though, it has been moved to http://qt-project.org/doc/qt-4.8/qt-conf.html – Clodéric Aug 06 '14 at 14:01
  • I confirm the ".." trick also works for version 4.8.2. This should actually be chosen as the correct answer. – Fabio A. Mar 30 '16 at 14:49
  • If got correct paths from `qmake -query` and wrong path in generated Makefiles: delete .qmake.cache file – krrr Dec 09 '16 at 14:21
9

This is a 'builtin' compiled into qmake from qconfig.cpp. The best way is to reconfigure Qt with another -prefix and rebuild unfortunately. For most other variables, you can use a .qmake.cache file. See

http://doc.qt.digia.com/qt/qmake-environment-reference.html

for more info

macetw
  • 1,640
  • 1
  • 17
  • 26
Henrik Hartz
  • 3,677
  • 1
  • 27
  • 28
2

As pointed out by Henrik Hartz, QT_INSTALL_PREFIX is built-in and can't be changed. However, if you just want to work around having to rebuild Qt temporarily, then you can try the following:

Query qmake for it's install prefix, recreate the reported directory structure, and use a symlink or hardlink to where the relocated Qt version is. E.g. on Linux

  • Get the path reported by /new/Qt/location/bin/qmake -query QT_INSTALL_PREFIX. Say this reports /Parent/Dirs/Prefix.
  • Create any parent directories of the path, e.g. mkdir -p /Parent/Dirs/
  • Symlink to new location, e.g. ln -s /new/Qt/location /Parent/Dirs/Prefix

The above can be also useful if you have a bunch of developers who need to work with the same prebuilt version of Qt, where this Qt version isn't necessarily copied to the same path on all the developers' computers, and where you only need to bundle the Qt shared libs with you application for end users (i.e. you won't be shipping headers or build tools).

Rob
  • 1,350
  • 12
  • 21