Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.

Including .pro Files

From Qt Wiki
Revision as of 15:57, 14 January 2015 by Maintenance script (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

English Malay Spanish German French Български

Including pro-files into pro-files

QMake’s project files sometimes need to rely on the include feature. This is a great tool, but there are some tricks of the trade to be aware of.

First up, a convention, pro-files meant for inclusion in other pro-files are commonly named *.pri, just to indicate that they are for inclusion. This also means that qmake does not find them, but uses the appropriate pro-file instead.

In a pro-file, you have two important variables: INCLUDEPATH and DEPENDPATH. The first is used by the C++ compiler when resolving #include statements, while the latter is used by qmake when trying to determine what to build in which order.

To create a truly movable source tree, the pri-files update these variables appropriately. My trick to do that is to rely on the current working directory. You find that by running the $$system(pwd) command (on Unix/Linux only – sorry).

Within the qmake variable reference [doc.qt.nokia.com] , there are variables that may help find the current working directory (Tested on Windows ). A couple of these are:

  • PWD [doc.qt.nokia.com]
    • This variable contains the full path leading to the directory where the qmake project file (project.pro) is located.
  • OUT_PWD [doc.qt.nokia.com]
    • This variable contains the full path leading to the directory where qmake places the generated Makefile.
  • Usage of the $$ prefix is detailed here [doc.qt.nokia.com] .

When having setup the include and depend paths, it is just a matter of adding to the SOURCES, HEADERS, RESOURCES and FORMS sections.

To summarize, here is a small example:

Finally, in the pro-file, simply add the pri-file by calling include:

Caveats

This solution seems to be too clever to the translation tools. To be able to use lrelease and lupdate, you must rely on less dynamic pro/pri-files, or simply find a way to generate a custom pro-file that you just use for translations.

Categories: