[SOLVED] [File Organization] Creating an organized project with Qt Creator
Page |
1 |
Hello Qt devs!
I’m developing a Qt GUI using Qt Creator. By default, when you create a new file (be it a header, a source file…), it puts in the current directory of your project.
Is there a way to add new folder, say, I want to put all my dialogs inside a folder, inside Qt Creator so that the .pro updates itself, or should I do that outside Qt Creator and update the .pro myself?
Also, this may not be the place to ask this, but do you have general tips on how to organize a project which has a lot of different classes?
Thanks everyone!
19 replies
Take a look at how Qt Creator does this: http://gitorious.org/qt-creator
We use .pro and .pri files to group files into libraries and plugins (with their files in separate directories).
This is how I organize my bigger projects (using .pri files):

I use pri files like this:
- INCLUDEPATH += $$PWD
- DEPENDPATH += $$PWD
- SOURCES += source1.h\
- source2.h
- HEADERS += header1.h\
- header2.h
and in the main project .pro file:
- include(gui/gui.pri)
- include(core/core.pri)
- include(fileformats/fileformats.pri)
etc.
It works perfectly in Qt Creator (if you do right click on the appropriate folder you can add files to that .pri like you would to a normal project).
Just to add to that you also have the possibility to add multiple projects to a bigger projects using the qmake subdirs template. This basically just tells qmake to build all the projects you specify (and in the order you specify):
- TEMPLATE = subdirs
- CONFIG += ordered #do it in the order specified
- SUBDIRS = uis languages programmers
Sorry to play threadcromancer, but I want to organize my files like this. I can see how to create a new text file and rename it to .pri, but it just gets sorted under Other Files. Never worked with plugins before. Can someone please write a step-by-step on how to organize files like in the image posted above?
EDIT: Hm…ok I’m guessing it’s add library? Didn’t think of that before. BTW, what does the following mean for the .pri file? Specifically $$PWD?
- INCLUDEPATH += $$PWD
- DEPENDPATH += $$PWD
When you create add a text file and rename to .pri in Qt Creator, it will take some time before Qt Creator parses your new files and recognizes the new folder structure. When it does, your project will look like the picture above.
And $$PWD dereferences the environment variable PWD, or print working directory, which is the directory you set for your project in Qt Creator, if I remember well.
I used this link to get information : http://stackoverflow.com/questions/1417776/how-to-use-qmakes-subdirs-template
So I got this stuff working. I uploaded the project to a git repository and cloned it to another computer. However, the project fails to recognize pretty much every header file, one at a time. For example it says it doesn’t recognize one header file, but if I comment that out, then it doesn’t recognize a different header file, and so on. Any ideas on why Qt won’t recognize on one computer while it recognizes and compiles fine on the other? All the pri files and pro files are unchanged from the working computer.
You must log in to post a reply. Not a member yet? Register here!



