Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. [SOLVED] [File Organization] Creating an organized project with Qt Creator
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] [File Organization] Creating an organized project with Qt Creator

Scheduled Pinned Locked Moved Qt Creator and other tools
21 Posts 6 Posters 41.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    valandil211
    wrote on 20 Jun 2011, 15:22 last edited by
    #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!

    Joey Dumont

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tobias.hunger
      wrote on 20 Jun 2011, 16:08 last edited by
      #2

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

      1 Reply Last reply
      0
      • V Offline
        V Offline
        valandil211
        wrote on 20 Jun 2011, 16:31 last edited by
        #3

        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?

        Joey Dumont

        1 Reply Last reply
        0
        • L Offline
          L Offline
          loladiro
          wrote on 20 Jun 2011, 17:49 last edited by
          #4

          This is how I organize my bigger projects (using .pri files):
          !http://dl.dropbox.com/u/32965023/Pri.png(Screenshot)!

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

          1 Reply Last reply
          0
          • V Offline
            V Offline
            valandil211
            wrote on 20 Jun 2011, 17:51 last edited by
            #5

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

            Joey Dumont

            1 Reply Last reply
            0
            • L Offline
              L Offline
              loladiro
              wrote on 20 Jun 2011, 17:55 last edited by
              #6

              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
              @

              1 Reply Last reply
              0
              • V Offline
                V Offline
                valandil211
                wrote on 21 Jun 2011, 11:58 last edited by
                #7

                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?

                Joey Dumont

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  loladiro
                  wrote on 21 Jun 2011, 15:39 last edited by
                  #8

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

                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    valandil211
                    wrote on 21 Jun 2011, 16:17 last edited by
                    #9

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

                    Thanks!

                    Joey Dumont

                    1 Reply Last reply
                    0
                    • L Offline
                      L Offline
                      loladiro
                      wrote on 21 Jun 2011, 16:24 last edited by
                      #10

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

                      1 Reply Last reply
                      0
                      • V Offline
                        V Offline
                        valandil211
                        wrote on 21 Jun 2011, 16:26 last edited by
                        #11

                        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!

                        Joey Dumont

                        1 Reply Last reply
                        0
                        • P Offline
                          P Offline
                          Plissken
                          wrote on 13 Jul 2012, 06:42 last edited by
                          #12

                          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@

                          1 Reply Last reply
                          0
                          • V Offline
                            V Offline
                            valandil211
                            wrote on 13 Jul 2012, 12:24 last edited by
                            #13

                            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.

                            Joey Dumont

                            1 Reply Last reply
                            0
                            • S Offline
                              S Offline
                              Skylar
                              wrote on 13 Jul 2012, 13:01 last edited by
                              #14

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

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

                              1 Reply Last reply
                              0
                              • P Offline
                                P Offline
                                Plissken
                                wrote on 18 Jul 2012, 23:26 last edited by
                                #15

                                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.

                                1 Reply Last reply
                                0
                                • V Offline
                                  V Offline
                                  valandil211
                                  wrote on 19 Jul 2012, 12:49 last edited by
                                  #16

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

                                  Joey Dumont

                                  1 Reply Last reply
                                  0
                                  • P Offline
                                    P Offline
                                    Plissken
                                    wrote on 19 Jul 2012, 19:52 last edited by
                                    #17

                                    @#-------------------------------------------------

                                    Project created by QtCreator 2012-06-27T21:24:38

                                    #-------------------------------------------------
                                    include(internal_lib/statsheet/statsheet.pri)
                                    include(internal_lib/widgets/widgets.pri)
                                    include(internal_lib/utility/utility.pri)

                                    QT += core gui

                                    TARGET = Singularity
                                    TEMPLATE = app

                                    SOURCES += main.cpp
                                    mainwindow.cpp \

                                    HEADERS += mainwindow.h
                                    singularity.h

                                    OTHER_FILES +=@

                                    1 Reply Last reply
                                    0
                                    • V Offline
                                      V Offline
                                      valandil211
                                      wrote on 19 Jul 2012, 20:00 last edited by
                                      #18

                                      Ok, I'm lost.

                                      What do you comment out for a header file not to be recognized? And what do you mean, not recognized? It doesn't show up in the left-hand-side list? Since I use .pri files, I always get the hierarchy shown by loladiro.

                                      Joey Dumont

                                      1 Reply Last reply
                                      0
                                      • P Offline
                                        P Offline
                                        Plissken
                                        wrote on 19 Jul 2012, 20:07 last edited by
                                        #19

                                        By not recognized I mean a compiler error. The error that I get is:

                                        error: C1083: Cannot open include file: 'internal_lib/widgets/sheet_wp.h': No such file or directory

                                        I tried commenting out the include statement that includes sheet_wp.h, but I only got another of the same error but for a different header file. It's strange because Qt Creator recognizes all the files in the Project pane and all the files are in the right folders.

                                        1 Reply Last reply
                                        0
                                        • P Offline
                                          P Offline
                                          Plissken
                                          wrote on 19 Jul 2012, 20:48 last edited by
                                          #20

                                          Wow. Fixed it but I don't completely understand why it worked. I looked up the definition of PWD because I didn't fully understand what it meant:

                                          "The PWD variable specifies the full path leading to the directory containing the current file being parsed. This can be useful to refer to files within the source tree when writing project files to support shadow builds."

                                          The word shadow builds caught my attention. I noticed that on the original project it was using a shadow build and the ones I've copied over weren't. I reloaded the pro file and this time selected shadow build option, now it compiles fine.

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved