Important: Please read the Qt Code of Conduct -

Bulding / adding subprojects ??

  • After RTFM

    I found "include" build-in function.

    Is is really that simple to have project with sub projects ?

    Any gotchas?

    qmake provides a number of built-in functions to allow the contents of variables to be processed. The most commonly used function in simple project files is the include function which takes a filename as an argument. The contents of the given file are included in the project file at the place where the include function is used. The include function is most commonly used to include other project files:

  • Lifetime Qt Champion


    It depends on what you mean by subproject.

    If you mean you would like to have several different projects built under the umbrella of one, then you should use the subdirs template.

  • @SGaist For now I would like to be able to open QtCreator and load two projects at once ( yes I can do the separately, no issue ) and be able to share/ use both as a single project.
    I can "add existing files" to my main project but running into some weir problems .

    I did try to add "directories" but was unable to do so.

    I am just looking to have a convenient way to share resources without "cut and paste". It keeps introducing strange unwanted stuff doing so.

    I was retentively successful combining projects in another IDE , however, I am not so sure how QTCreator will react. Maybe it won'tt be worth the time spent.

    Again - I am just looking for a convenient way , it is not a show stopper by any means.

  • As expected - it sounded too simple to work by just adding "include" .

    include (/home/d/CAT_MAIN/TEST_Application/ )

    1.I build two identical projects and "included" the subproject in main project.
    Obviously - Build main project complains of multiple definitions

    Now here are my options

    1. rename duplicate file
      did not help
    2. delete duplicate file
      now the subpropject is no longer full app and without main won't obviously compile by itslef.
      or ??
    • not so easy to fix.
    1. Minor changes in subproject do not trigger rebuild - looks as the safest way is to always "rebuild all; " - sort of expected

    2. I am adding new QtWIdget to sub-project - will be watching for smoke...

    Now the main project build reports this error:

    :-1: error: No rule to make target 'app_form.ui', needed by 'ui_app_form.h'. Stop.

    It looks that I need to try plain C++ class , no widget derived.

    Same problem

    :-1: error: No rule to make target 'app_test_class.cpp', needed by 'app_test_class.o'. Stop.

    OK. so WHERE / HOW I instruct main project - what "rule" is missing and where?

    PS I did look at the link and it is way over my head , besides I do not want to get involved with "Windoze"

    So for now adding "include ( project) " to main project is bogus - not enough to make it work... not even a good solid start...

  • here is what Mrs Google found

    time to RTFM


    OK, let me simplify things,
    AFTER adding the .pro file , using the above link, I get a NEW menu options
    when clicking on the "project "
    simple "Adding subproject..."

    My qustion to the forum
    "which option in the "multiprooject file" actually triggers thus option?

    And the answer is

    TEMPLATE = subdirs

    placed in main project . .pro file makes add new subproject a child's play

    • time to ditch
      "include (project file .pro) "

    BUT - there is always a BUT

    when BOTH main project and FIRST subproject have main window -
    the project will try execute and "show " both!
    Of course if BOTH have defunct placement only the subproject will actually be visible "on top" -. It can be moved...
    BUT where is the main project main window ?
    Nowhere because the process gets stuck running "standard" QApplication "llop" in first suboproject.

    The main question - how does main project let FIRST subproject to execute anyway ??

    What option / setting is missing ??

    Or is the only option to actually execute the sub projects ??
    That is NOT what I need - I need to "inlcude " the subprojects , not to run them individually.

    Maybe the "include(project) is needed after all...

  • @AnneRanch
    Allow me to rephrase the next question.

    Assuming the purpose of having project with subprojects is to "build a sub -project and when it works add it to the main project" .

    That , to me , means the sub project has to be build and run independently from the main project. To do so it has to have "main" like any other software.
    It does that.

    Hence when sub project is added via " New Subproject..." it does compile / build / run independently as desired.

    However, when main project is run it starts with "main window" then it runs "main window" of first sub project. Since subproject is build around / inside QApplication a(argc, argv); ( I do not know how else to call it ) THE PROCESS STOPS INSIDE QApplication loop of first sub project....
    The sub project does nothing but shows main window for now.

    I am assuming I am missing some instruction to "break" this chain and be able to incorporate sup project code into main project without actually running the sub projects.

    Or am I totally off in the left field ??

  • Just short add

    1. I have successfully added plain C++ class to main project

    2. The new cpp and h files are nowhere to be found in "projects" view

    3. I can no longer add "New.." to main project - no such option...

    4. I can no longer add "New Subproject -> Files and Classes" - no data in view
      ( see #1 This is what I used to add now invisible C++ class to main project)

    5. I can still add New Subproject.

    I am not a happy camper and RTFM no longer helps..

  • @AnneRanch
    Sorry group , but this is turning into proverbial can of worms.
    Nothing works same each time it is used and seldom the way one expect.
    It looks as adding
    TEMPLATE = subdirs
    in .pro file takes hold after ALL builds are used - I mean "Build" "Run qmake" "Rebuild" - perhaps one of them does it.

    When running just the main project, without adding sub project, I get dialog asking to select executable.

    That would solve the issue I had executing real project with subprojects , but I have no idea WHAT is plain Qt project executable . No .exe - In linux ! How do I know / identify "linux project executable ?" The dialog does not present executable files only so it is up to me know which one it is.

    So _ I expect that there would be ONE executable WHEN there is only main project.

    Then I would expect to be ask to select the executable - main project _ when I add my my first sub project.

    The I get this


    OK, there is no executable - BUT how do I get back to the original annoying dialog which let me select one?

    See what I mean ?
    First I get request to select executablee when there is only one ( running main project without adding sub projects) , now I am told there is no executable without slightest hit HOW to add /select one...

    Note the funky TAB title.

  • Lifetime Qt Champion

    It seems you did not understand the concept behind the subdirs template.

    Each project that composes it is a complete project. It's not a way to structure your files for a single project.

    See for example this tutorial.

    If Qt Creator does not find any executable, then it means that none of your sub-project implements the app template.

  • @SGaist

    Here is a clean new " C_Project " "looking for executable "

    bfe43c0d-4d59-40e4-81f6-1c2a2b21e724-image.png No executable specified.

    Which is "executable" ?


    Help me solve that first.

  • Lifetime Qt Champion

    Remove the "TEMPLATE = subdirs". You're overwriting the original value.

  • Here is normal" run , without the

    TEMPLATE = subdirs

    which enables "New subprogram..."

    My interim conclusion
    enabling "New subprogram " causes the "mising executable".
    I must be missing something else in .pro file

    WHAT is missing ?
    WHY and HOW to fix it ?


  • Lifetime Qt Champion

    @AnneRanch said in Bulding / adding subprojects ??:

    WHAT is missing ?

    The understanding of how the subdirs template works.

    @AnneRanch said in Bulding / adding subprojects ??:

    WHY and HOW to fix it ?

    For why: to make it work I guess.

    For the how, I already provided a link to a tutorial that explains the concepts and one to a wiki page that also explains how it works.

    So you should start by taking a step back, create a proper subdirs project from scratch and once your have it properly building and running, move back to your project.

  • @SGaist
    You are the man...
    Sure , makes perfect sense - when app is replaced by subdirs all hell breaks loose.

    TEMPLATE = app needs to be " reinstalled " , preferably in main project..

    I'll go back to the first multi project which still somewhat works to see how
    TEMPLATE = app was handled there.
    There the problem was - the main "executable" somehow connected to the sub project "executable"....

    This will take some time, but I;ll keep you posted .

  • Lifetime Qt Champion

    First thing: you can't just replace the template type in your application .pro file.

    The subdirs template requires a structure to be followed. As explained in the links I have posted.

  • @SGaist said in Bulding / adding subprojects ??:

    @AnneRanch said in Bulding / adding subprojects ??:

    WHAT is missing ?

    The understanding of how the subdirs template works.

    Yes, looks as the whole concept of "subproject" is good for what I wanted - be able to load multiple projects .

    The only weird issue is the the "main project" is actually one, preferably the first "subproject".
    But it will do.

    The basic Qt "subproject" concept is to have multiple projects "under one roof".
    Unfortunately some tutorials concentrate on expanding this simple, primarily administrative concept thus making the implementation far more complicated then it is .

    When one follows these tutorials , as I did , the QtCreator implementation is completely covered and it leads to few dead ends.

    Here is my conclusion:

    Start with :

    1. New File or Project -> Other Project ->Subdirs Project
      then use
    2. project -> "New Subproject..." and select desired project type

    finally use
    3. and your newly added FIRST (sub) project will (build and ) execute.

    repeat step 2 3 as necessary

    1. code / debug each added sub project as you would any other SINGLE project.

    2. Qt will build / rebuild every sub project as necessary.

    Essentially all is needed is to know to implement this scheme

    TEMPLATE is your friend

    In closing I really appreciate all the help received from the discussion participants.

    Like to hear from anybody who successfully Imported existing sub project using the "new subproject... " options.

  • @AnneRanch
    you are a great person. I searched many sites all day long. However, I was more confused about what to do. After reading and applying what in your last post, I've literally succeeded. Really thank you so much. Have a nice day..

Log in to reply