10
votes

I want to copy an audio plugin to my target directory since I need it for deployment.

It lives in <PATH_TO_QT_INSTALL>\gcc\plugins\audio

I don't know what variable I can use to reference the install path inside my /pro file.

The line of code I want to add is something like this:

QMAKE_PRE_LINK += cp $$PATH_TO_QT_INSTAL/gcc/plugins/audio/* $$DESTDIR/lib || :;

There is an environment variable called %{CurrentProject:QT_INSTALL_BINS} that gets me to $$PATH_TO_QT_INSTAL/gcc/bin which I could use, but I seem to be only able to use this in the qt creator gui build settings which is no good to me since these settings live in the .pro.user file. WHY doesn't qt have a generic build settings mechanism : ( ... (that's just a side question, no need to answer)

My question is how can I reference the qt install path in my pro file, is there a variable that can do this, or any other way?

3
You can get path to the bin directory by running qmake -query QT_INSTALL_BINS command, but I don't know how will it help you.vahancho
hmm.... actually that gives me a nice idea. I already have a deployQt.sh script that I made which uses ldd to find all the qt libs that are needed and copy them to my lib folder... so I can probably add this qmake query command of yours into that. Let me try it out, if it works I'll let you know and you can put it up as an answer, thanks.code_fodder
From the other hand, if you have access to qmake you know its path, which is the QT_INSTALL_BINS.vahancho
@vahancho I don't understand what you mean, can I use QT_INSTALL_BINS somewhere? - it does not seem to be a populated variable within the pro file?code_fodder
You said, that you can add qmake query command to your shell script. This means that you already know path to the qmake executable to call it, right? If so, that path is the path to the Qt bin directory, where the qmake lives. So, you can define an environment variable in your script so that it will be available from the pro file.vahancho

3 Answers

8
votes

For Qt4 and Qt5, looks like $$[QT_INSTALL_LIBS] is what you want? Can't confirm first-hand this works though.

See https://forum.qt.io/topic/65778/qmake-and-qt-installation-root-directory/2 and http://doc.qt.io/qt-4.8/qmake-advanced-usage.html.

5
votes

Another solution (may be not as fancy as above with $[QT_INSTALL_LIBS] but I used it already for quite a long time:

TEMPNAME = $${QMAKE_QMAKE}
QTPATH = $$dirname(TEMPNAME) 

then you can reference it like this (for example to access some private headers) or to copy things:

INCLUDEPATH += $$QTPATH/../../Src/qtbase/src/sql/kernel
4
votes

The variable QT_INSTALL_PREFIX seems to be what you want, but it highly depends on how Qt has been installed.

For more fine-tuning depending on the exact qt directory you're interested in, the following command will give you an exhaustive list of persistent properties of qt:

/path/to/qmake -query

# Output
# QT_INSTALL_PREFIX:/path/to/Qt
# QT_INSTALL_ARCHDATA:...
# ...

The already mentioned QT_INSTALL_LIBS is listed there for example. Once you find the variable corresponding to your usecase, you can use it in your .pro file as it was already mentioned, i.e. with $$[QT_INSTALL_PREFIX] for example.

Note: from the qmake documentation, squared brackets should be used for qmake properties ($$[])

Versions: tested with Qt 5.6.2 and qmake 3.0