Zac Gross

Code & More

Nested Folders in Qt Creator

| Comments

At first glance qt creator seems to be a feature rich ide however it still lacks many basic features such as being able to add sub folders for code to projects through the project explorer window. The following tutorial demonstrates how to get around the ide limitation by adding the folders manually.

The goal is to achive the below folder strucutre, project being the root, and “ModuleA” being the folder we need to add.

1
2
3
4
5
6
7
--Project
--/ModuleA/
----a.cpp
----a.h
----b.cpp
----b.h
--main.cpp

Start by navigating to the projects root directory, and create a new folder:

1
 mkdir ModuleA

Create a new file inside named “modulea.pri”. If you are going to copy existing files into this new folder you need to add them to the pri file. (Adding new files can be done through the qt creator gui once the project is configured properly)

Note the path names must be relative from the project root

title:ModuleA.pri
1
2
3
4
5
SOURCES += ModuleA/a.cpp \
    ModuleA/b.cpp \

HEADERS += ModuleA/a.h \
    ModuleA/b.h \

Now we need to include the new .pri file for the folder in the project configuration. Open up the .pro file located in the project root directory and add the following line:

title:Project.pro
1
include(ModuleA/ModuleA.pri)

Reload the project, the new ModuleA folder should now be visible as a subfolder in your main project. Right clicking on it will give you the option to add new files. Simply repeat the above process for each new sub folder you wish to add.

Comments