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?
9 Answers
Answer : 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.
The folder must exists, Qt will not create it for you.
Qt takes care of the path in your .pro file.
That's it !
It only seems to be impossible to create sub-directories in QT-CREATOR.
Try the following:
- Create a number of sub-directories, with a file-explorer or by command line within the project-folder (for example net/, gui/, test/, data/ ...)!
- Move exisiting files into these new folders. And change their paths within the *.proj file!
- 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.)
Here's what I have done:
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".
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
- Rebuild your project to test.