tags:

views:

949

answers:

3

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?
A: 

Extracted from Qt 4.5: Managing Projects:

The .pri file contains the list of source files, header files, .ui files, and .qrc files in the project.

For more about these files and their OSs:

  • A .vcproj file containing Windows-specific settings and listing the files in the project.
  • A .pro file containing Unix and/or Mac OS X specific settings.
  • A .pri file (a qmake include file) listing the files in the project.

I suggest you to take a look on the link.

Nathan Campos
+1  A: 

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.

Caleb Huitt - cjhuitt
A: 

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.

Fred
this answer is not so descriptive, but it solves my problem, thanks
Karel Bílek