Important: Please read the Qt Code of Conduct -

Exam question about qmake, just for advance users.

  • What projects will be included if your project file contains the next code:

    TEMPLATE = subdirs
    MODELS = $$files(models/*.pro,true)
    for(m, MODELS){
        MODEL= $$split(m, "/")
       count(MODEL, 3) {
           SUBDIRS += $$m

    A) All the projects recursively inside models
    B) All the projects inside each direct subfolder of folder models

  • Lifetime Qt Champion


    Do you mean you want to know what this should be doing because you got it as a question in an exam ?

  • not really, i found it writting the building code for one of my projects.

    I really cant find the logic.....

    The result is the (A)
    And for more fun, if you print SUBDIRS, it contains exactly the paths as i would be (B)
    if instead of:
    SUBDIRS += $$m

    i write:
    SUBDIRS += $$member(MODEL,0)/$$member(MODEL,1)/$$member(MODEL,2)

    it works.

    i must miss a basic about qmake or i must miss a basic about logic.

  • Lifetime Qt Champion

    It's because you are trying to get files that match the "models/*.pro" pattern which is not the same as retrieving files from a folder named models and its subfolders following the pattern "*.pro"

  • that is what i pretend with the $files, as i didnt find a better way.

    and what i pretend with the loop for, is to check which ones, splitting it by "/", give 3 parts:

    1. "model"
    2. folder
    3. files".pro"

    If i use:
    it adds to SUBDIRS the ones i want, but QtCreator is adding everything

    If i add:

    it adds the sameones to SUBDIRS, but QtCreator detect almost just the ones in SUBDIRS (a couple more than shouldnt)

    As i realized, when try to build it, it seems to process only the correct ones... (the Makefile is correct!) so i believe there is a bug in QtCreator. Can be?

  • Lifetime Qt Champion

    If you mean that Qt Creator shows all of your subdirs while only part of them are built then no, its not a bug (well I don't see it as a bug). AFAIK, Qt Creator shows the complete source tree

Log in to reply