How to create a subdirectory for a project QtCreator?

Viewed 73004

I would like to divide my Qt project into several directories because it is growing pretty large. However, when I click on browse in QtCreator, there is no 'Add directory' and no such thing in 'Add new'. Can this be done somehow?

10 Answers

One method you could use is to add a project include file for each sub directory.

Qt Creator displays these in the GUI in a nested fashion, and allows you to add files to them.

e.g.

in project.pro

include(folder1/include.pri)

in folder1/include.pri

HEADERS += MyClass.h
SOURCES += MyClass.cpp

etc

Here's what I have done:

  1. In the Project Folder (outside the IDE), create Directories that you'd like to put your code in and move your source files into those directories.

    • Say you put "foo.cpp" and "foo.h" in the directory "foo".
  2. In your "*.pro" file, go to each line that references the source files you moved and add the directory name, followed by '/' in front of the source file name.

.pro before Step 2:

SOURCES += main.cpp \
foo.cpp

HEADERS  += \
foo.h \

.pro after Step 2:

SOURCES += main.cpp \ 
foo/foo.cpp

HEADERS += \
foo/foo.h
  1. Rebuild your project to test.

you can add folders in your folders manager but they should contain a file, then go QT and right-click on your project then click on "add existing directory" and select your folder. if the folder is empty it's not going to show up.

Related