How to create a subdirectory for a project QtCreator?

QtQt CreatorQmake

Qt Problem Overview


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?

Qt Solutions


Solution 1 - Qt

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

Solution 2 - Qt

Answer : https://stackoverflow.com/questions/24959959/how-to-create-a-folder-or-a-subdirectory-for-a-project-in-qtcreator

Prior to QT Creator 3.1.x, you can right-click on your project -> "add new..." and change the path to the folder you want.

Qt add new...

The folder must exists, Qt will not create it for you.

Add a new class and change the default folder Qt

Qt takes care of the path in your .pro file.

Qt takes care of the path in your .pro file

Qt takes care of the path in your .pro file

That's it !

Solution 3 - Qt

Just had the same issue, and found out a relatively simple answer.

All you need to do to move file.cpp to newFolder is to rename the file (right click -> Rename) to newFolder\file.cpp.

Qt Creator will move it to the new folder and automatically update the .pro file.

Solution 4 - Qt

Starting from version 1.2.90 Qt Creator shows subfolders which exist in project's folder as branches in project's tree if only Filter tree option is not set to Simplify tree.

Solution 5 - Qt

It only seems to be impossible to create sub-directories in QT-CREATOR.

Try the following:

  1. Create a number of sub-directories, with a file-explorer or by command line within the project-folder (for example net/, gui/, test/, data/ ...)!
  2. Move exisiting files into these new folders. And change their paths within the *.proj file!
  3. Create new also files from beginning within the new folders (By AddNew...)!

... QT-CREATOR displays only such folders which contain files that are written with their names into the *.pro or a *.pri file. At root level QT-CREATOR distinguishes between HEADERS, SOURCES, FORMS and OTHER FILES. Within these root folders you can find project-own subfolders, repeatedly. (Not covered in this text is splitting into sub-projects.)

Solution 6 - Qt

When you create a new Class in your Qt-Project, you can choose the path in this wizard and hereby specify new folders like DAL, BO, UI, ...

Solution 7 - Qt

You can create a sub-directory as long as you have a file you wish to create in it. Go to the parent directory, and "Add" a file to it. "Browse" for the location and create a new folder inside the browse window. Agreed, that is not quite intuitive.

Solution 8 - Qt

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".
  1. 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

3. Rebuild your project to test.

Solution 9 - Qt

When my 'data' directory only had one sub-directory 'model' it just appeared as "data/model". After adding 'dao' as another sub-directory it displayed data with the traditional +/- manner to reveal model and dao.

Solution 10 - Qt

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiongruszczyView Question on Stackoverflow
Solution 1 - QtNickView Answer on Stackoverflow
Solution 2 - QtErowlinView Answer on Stackoverflow
Solution 3 - QtAvidan BorisovView Answer on Stackoverflow
Solution 4 - QtPiotr DobrogostView Answer on Stackoverflow
Solution 5 - QtCWIMMERView Answer on Stackoverflow
Solution 6 - QtMiguel RodriguezView Answer on Stackoverflow
Solution 7 - QtmichaeljtView Answer on Stackoverflow
Solution 8 - QtNicholas MathernView Answer on Stackoverflow
Solution 9 - QtJames WaldView Answer on Stackoverflow
Solution 10 - QtlovethisstuffView Answer on Stackoverflow