Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using .pri files in Qt

Tags:

qt

qt-creator

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?
like image 944
Karel Bílek Avatar asked Dec 28 '09 01:12

Karel Bílek


People also ask

What is .PRI file in Qt?

This is usually called Project Include File.

What is a qmake file?

qmake provides a number of built-in functions to enable the contents of variables to be processed. The most commonly used function in simple project files is the include() function which takes a filename as an argument.

What does run qmake do?

The behavior of qmake can be customized when it is run by specifying various options on the command line. These allow the build process to be fine-tuned, provide useful diagnostic information, and can be used to specify the target platform for your project.


2 Answers

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.

like image 173
Caleb Huitt - cjhuitt Avatar answered Sep 22 '22 22:09

Caleb Huitt - cjhuitt


My guess from looking at your screenshot is that QtCreator doesn't find the header files listed in the .pri file. If your .pri file is located in a different directory than your .pro file (which seems to be the case here), Qt looks for the files listed in the .pri file in the same directory as the .pri file (not the .pro file), and any relative path will be resolved from that directory.

When a file can't be found, QtCreator silently ignores it and simply doesn't add it to the folder in the projects view. If, for example, you used the full path for line.h, circle.h and bezier.h in your include.pri file, as soon as you save the file, you'll see them appear in the projects view. The key now is simply to figure out what is the appropriate relative path pointing to those files relative to the .pri file.

like image 29
Fred Avatar answered Sep 24 '22 22:09

Fred