Qt: *.pro vs *.pri

QtQmakeQtcore

Qt Problem Overview


What is the difference between *.pro and *.pri configuration files for qmake?

What should go into a *.pro file and what should go into a *.pri file?

Qt Solutions


Solution 1 - Qt

There is one main difference between their targetted reuse:

.pro

This is usually called Project File.

.pri

This is usually called Project Include File.

As you can see in their names, the main difference is that .pri files are meant to be include files. That is similar to including modules in programming language to share the functionality, essentially.

You will be able to write the common settings and code into those .pri files and include them from several .pro files as the need arises. This is how you would use it in practice:

foo.pri
FOO = BAR
hello.pro
...
include($$PWD/foo.pri)
...
world.pro
...
include($$PWD/foo.pri)
...

This way, the commonality would be available both in hello.pro as well as world.pro. It does not make much of difference in this scenario, but when the shared functionality gets longer, it will save you some writing as well as sync'ing, bugfixing, and so on.

You could even include a .pri file inside another .pri file if you wish. You could also include .pri files in different subprojects, etc. It is very nice.

The syntax is the same, however, for both the .pro and .pri files. In the end, you would run qmake on the .pro files, and that is also what qmake generates for you if you do not have a project file existing and you intend to use qmake -project.

You can read more about the include function in here:

> include(filename) > > Includes the contents of the file specified by filename into the current project at the point where it is included. This function succeeds if filename is included; otherwise it fails. The included file is processed immediately. > > You can check whether the file was included by using this function as the condition for a scope.

Just to be complete, there are also .prf Project Feature Files and .prl Project Linker Files, but as an end user, you do not need to deal with that for now.

Solution 2 - Qt

A .pro file is what you would run QMake on. A .pri file is included by a .pro file. Other than that there is not much of a difference between the two.

Example usage could be if you have different builds which need different options. You could put shared information in the .pro, while deferring the options to various .pri files. A bit more information, although admittedly not much more, can be found here.

Solution 3 - Qt

The format of the .pri files is exactly the same as the format of the .pro files. The main difference is one of intent; a .pro is what most people would expect to run qmake on directly, while a .pri is to be included by a .pro. When you instruct qmake to include another file, it just processes the commands in that file as if it were in the current file.

For Reference: *.pro vs *.pri

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRoman ByshkoView Question on Stackoverflow
Solution 1 - QtlpappView Answer on Stackoverflow
Solution 2 - QtBartView Answer on Stackoverflow
Solution 3 - QtAlphaMaleView Answer on Stackoverflow