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. QT Creator "subdirs" project

QT Creator "subdirs" project

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
14 Posts 6 Posters 11.0k Views
  • 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.
  • M Offline
    M Offline
    mindgames
    wrote on last edited by
    #1

    Hi all,

    I've just started following along with Stanford's CS106X course through their online course material, to brush up on my (quite mediocre) C++. The course uses QT Creator, so I've installed version 4.0.2 on my OS X system.

    The course material includes a QT "starter project"
    (http://web.stanford.edu/class/archive/cs/cs106b/cs106b.1162/qtcreator/simple-project.zip)
    that includes the "Stanford CPP" libraries. Note that this is not a pre-compiled library, rather, the source (.h and .cpp) files are present. I would like to use these libraries for various mini-projects I might be making as I follow along the course.

    What I would like to know about is the most "hassle-free" way I could keep my projects together and automatically import the requisite libraries.

    I noticed QT Creator allows making something called "subdir" projects. In the aforementioned starter project, the .pro file has the line

    TEMPLATE = app
    

    I tried changing this to

    TEMPLATE=subdirs
    

    and after Qt Creator re-parses the file, it allows me to right-click on the project name and chose the (previously greyed out) "New subproject" option.

    Now after I create a new subproject, is there something I can do to make the include files (and corresponding sources) available to it? I understand I should be able to put things into the .pro file to tell the build system where everything is (although I haven't tried it yet), but is there a more straightforward way, by virtue of the "subproject" relationship?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jan-Willem
      wrote on last edited by
      #2

      Does this help? https://wiki.qt.io/SUBDIRS_-_handling_dependencies

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mindgames
        wrote on last edited by
        #3

        Not sure; I think the document you linked is for when you want to share a pre-built library.

        I'm guessing my question isn't very well specified - all I wanted was a good way to create projects that allow me to #include "someheader.h" from the parent project (i.e. the Stanford CPP code) that the linker can resolve, without having to worry about relative paths or having to passing additional include/source directories to the build/linker system for every new project - or (alternatively) having to add a duplicate copy of the Stanford code I want to reuse in every project.

        This might seem like a frivolous requirement, but I guess I was just hoping to minimize the "cognitive load" (i.e. learning c++ - the language - without the added burden of having to understanding the IDE or build system right away. But maybe that's just me being lazy.)

        I suppose if I built the Stanford CPP sources as a static library first then I could use the ideas in the page you linked.

        In any case, thanks!

        T 1 Reply Last reply
        0
        • M mindgames

          Not sure; I think the document you linked is for when you want to share a pre-built library.

          I'm guessing my question isn't very well specified - all I wanted was a good way to create projects that allow me to #include "someheader.h" from the parent project (i.e. the Stanford CPP code) that the linker can resolve, without having to worry about relative paths or having to passing additional include/source directories to the build/linker system for every new project - or (alternatively) having to add a duplicate copy of the Stanford code I want to reuse in every project.

          This might seem like a frivolous requirement, but I guess I was just hoping to minimize the "cognitive load" (i.e. learning c++ - the language - without the added burden of having to understanding the IDE or build system right away. But maybe that's just me being lazy.)

          I suppose if I built the Stanford CPP sources as a static library first then I could use the ideas in the page you linked.

          In any case, thanks!

          T Offline
          T Offline
          t3685
          wrote on last edited by
          #4

          @mindgames

          You can alternatively setup a pri file with all the Stanford code. And include that pri file in each of your separate projects. This way you would not need a subdirs project.

          https://wiki.qt.io/Including_.pro_Files

          M 1 Reply Last reply
          1
          • T t3685

            @mindgames

            You can alternatively setup a pri file with all the Stanford code. And include that pri file in each of your separate projects. This way you would not need a subdirs project.

            https://wiki.qt.io/Including_.pro_Files

            M Offline
            M Offline
            mindgames
            wrote on last edited by
            #5

            @t3685 This seems like a more attractive option, I'll look into it.. thanks!

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              Do you mean move all your files to the subproject folder used to build your library ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              M 1 Reply Last reply
              0
              • SGaistS SGaist

                Hi,

                Do you mean move all your files to the subproject folder used to build your library ?

                M Offline
                M Offline
                mindgames
                wrote on last edited by
                #7

                @SGaist said in QT Creator "subdirs" project:

                Hi,
                Do you mean move all your files to the subproject folder used to build your library ?

                Let me explain:

                This is the file structure I get when I unzip the starter project (i've left out some things I feel are non-essential):

                simple_project
                  - simple_project.pro
                  - lib
                    - StanfordCPPLib
                          - *.h
                          - *.cpp
                      - private
                          - *.h
                      - stacktrace
                          - *.h
                          - *.cpp
                  - src
                      - *.h
                      - *.c
                
                
                

                As per how the .pro file is configured, the student is expected to complete an assignment by writing all his code in the src folder, and he can just #include headers from StanfordCPPLib and hit "Build". However, this way allows only having one file containing main() in the src folder. What I would rather be able to do is make multiple projects relying on the same code (StanfordCPPLib), but which are otherwise independent of one another, each having its own main() function, and do it in a way that would allow me to keep all these "sister projects" together in the same hierarchy in a non-interfering way whilst making the least amount of additions to the .pro files or build system boilerplate.

                Even though this is just for learning purposes and I can conceive of several (inelegant) ways of getting around the issue, I was wondering what the best way would be in this situation.

                (I still have to look into @t3685's suggestion, at first glance it seems closest to what I want.)

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  A more flexible sub-project setup:

                  complex_project
                      - sub_project.pro
                      - lib
                          - lib.pro <- TEMPLATE = subdirs
                          - StanfordCPPLib
                                - StanfordCPPLib.pro
                                - StanfordCPPLib.pri <- will be included by your applications
                                - *.h
                                - *.cpp
                            - private
                                - *.h
                            - stacktrace
                                - *.h
                                - *.cpp
                      - apps
                          - apps.pro  <- TEMPLATE = subdirs
                          - my_app
                              - my_app.pro -> include(../../lib/StanfordCPPLib/StanfordCPPLib.pri)
                              - *.h
                              - *.cpp
                  

                  StanfordCPPLib.pri will contain statements like ÌNCLUDEPATH and LIBS to set things up for the projects using that library. Doing so will avoid duplication in your apps .pro file.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  2
                  • S Offline
                    S Offline
                    sujith D
                    wrote on last edited by
                    #9

                    @SGaist Is there an automatic way to generate a .pri file
                    from .pro of an existing project?

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Hi,

                      Not my knowledge.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • RaadR Offline
                        RaadR Offline
                        Raad
                        wrote on last edited by
                        #11

                        In your main pro file :

                        TEMPLATE = subdirs
                        SUBDIRS += \
                                ADD YOUR SUBDIR NAME HERE
                        
                        #To use ordered build:
                        
                        CONFIG += ordered
                        

                        In your subdir pro file:

                        TARGET=
                            ...
                        
                        QT  += 
                            ...
                        
                        SOURCES += \
                            ...
                        
                        HEADERS += \
                            ...
                        
                        FORMS += \
                            ...
                        
                        RESOURCES += \
                            ...
                        
                        SGaistS 1 Reply Last reply
                        0
                        • RaadR Raad

                          In your main pro file :

                          TEMPLATE = subdirs
                          SUBDIRS += \
                                  ADD YOUR SUBDIR NAME HERE
                          
                          #To use ordered build:
                          
                          CONFIG += ordered
                          

                          In your subdir pro file:

                          TARGET=
                              ...
                          
                          QT  += 
                              ...
                          
                          SOURCES += \
                              ...
                          
                          HEADERS += \
                              ...
                          
                          FORMS += \
                              ...
                          
                          RESOURCES += \
                              ...
                          
                          SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @Raad Please avoid ordered and specify the dependencies directly.

                          See this very good blog post.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          RaadR 1 Reply Last reply
                          4
                          • SGaistS SGaist

                            @Raad Please avoid ordered and specify the dependencies directly.

                            See this very good blog post.

                            RaadR Offline
                            RaadR Offline
                            Raad
                            wrote on last edited by
                            #13

                            @SGaist Thank you so much for pointing that out! I was not aware of this issue.

                            SGaistS 1 Reply Last reply
                            1
                            • RaadR Raad

                              @SGaist Thank you so much for pointing that out! I was not aware of this issue.

                              SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              @Raad A documentation update is in the works that will explain that.

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              2

                              • Login

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