June 20, 2011

Joey Dumont Joey Dumont
Lab Rat
116 posts

[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!

 Signature 

Joey Dumont

19 replies

June 20, 2011

Tobias Hunger Tobias Hunger
Mad Scientist
3150 posts

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).

June 20, 2011

Joey Dumont Joey Dumont
Lab Rat
116 posts

Thanks for the tip! Does Qt Creator recognizes this tree structure or does it list everything in the folders Headers, Sources and Forms ? Are the plugins in separate projects?

 Signature 

Joey Dumont

June 20, 2011

loladiro loladiro
Lab Rat
596 posts

This is how I organize my bigger projects (using .pri files):
Screenshot

I use pri files like this:

  1. INCLUDEPATH += $$PWD
  2. DEPENDPATH += $$PWD
  3. SOURCES += source1.h\
  4. source2.h
  5. HEADERS += header1.h\
  6. header2.h

and in the main project .pro file:
  1. include(gui/gui.pri)
  2. include(core/core.pri)
  3. 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).

June 20, 2011

Joey Dumont Joey Dumont
Lab Rat
116 posts

Thanks, that’s exactly what I was thinking of!

 Signature 

Joey Dumont

June 20, 2011

loladiro loladiro
Lab Rat
596 posts

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):

  1. TEMPLATE = subdirs
  2. CONFIG += ordered #do it in the order specified
  3. SUBDIRS = uis languages programmers

June 21, 2011

Joey Dumont Joey Dumont
Lab Rat
116 posts

I’m not sure how actually do this in Qt Creator. Do you create a new Qt Creator plugin project and modify the .pri so that they get included in your project?

 Signature 

Joey Dumont

June 21, 2011

loladiro loladiro
Lab Rat
596 posts

I usually just do New->Text File and change the extension to .pri!

June 21, 2011

Joey Dumont Joey Dumont
Lab Rat
116 posts

Ok, now I understand. You write it manually initially, then Qt Creator takes cares of it.

Thanks!

 Signature 

Joey Dumont

June 21, 2011

loladiro loladiro
Lab Rat
596 posts

Yeah, sorry I should have mentioned that. Maybe if have time, I’ll code a wizard for that and do a merge request.

June 21, 2011

Joey Dumont Joey Dumont
Lab Rat
116 posts

Yes, that would be incredibly helpful. However, I’m sure a little noob documentation in Qt Creator itself could be good. It may be my fault, but I didn’t find anything in Qt Creator’s docs about that.

Anyway, thank you for your answers!

 Signature 

Joey Dumont

July 13, 2012

Plissken Plissken
Lab Rat
18 posts

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?

  1. INCLUDEPATH += $$PWD
  2. DEPENDPATH += $$PWD

July 13, 2012

Joey Dumont Joey Dumont
Lab Rat
116 posts

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.

 Signature 

Joey Dumont

July 13, 2012

Skylar Skylar
Ant Farmer
47 posts

I used this link to get information : http://stackoverflow.com/questions/1417776/how-to-use-qmakes-subdirs-template

 Signature 

In most cases, the bug is mine. But of the remaining lines are correct.

July 19, 2012

Plissken Plissken
Lab Rat
18 posts

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.

July 19, 2012

Joey Dumont Joey Dumont
Lab Rat
116 posts

The only thing I could see that would cause that would be using absolute paths. Can you show us your .pro file?

 Signature 

Joey Dumont

Page  
1

  ‹‹ [SOLVED] lrelease with OUT_PWD      Debugging Symbian Emulator , but no call stack information and locals window blank ››

You must log in to post a reply. Not a member yet? Register here!