Using .pri files in Qt

Karel Bílek picture Karel Bílek · Dec 28, 2009 · Viewed 45.8k times · Source

This is a followup to this question How to create a subdirectory for a project in qt-creator?, where the first answer didn't work for me.

I resolved it by manually writing every file into the main .pro file, which is not that much harder, but I still wonder - how exactly .pri files work, and why the solution linked above didn't add the folders, but only the .pri files, so it looked like this in Qt creator:

Qt creator screenshot

So, my questions are:

  • What is the general format of the .pri files?
  • Why the solution above doesn't work?

Answer

Caleb Huitt - cjhuitt picture Caleb Huitt - cjhuitt · Dec 28, 2009

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.

The last time I looked at Qt Creator, it would do additional parsing and recognize that .pri files were separate, and list any headers/sources/ui/rc/pri files from that file specifically as a subdirectory, much like you see the include.pri files listed in the screenshot of this question.