Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QMake -- How to create a user variable, pass it to an included file, add 1 to the number in the included file.

QMake -- How to create a user variable, pass it to an included file, add 1 to the number in the included file.

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 736 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.
  • D Offline
    D Offline
    dwilliams
    wrote on last edited by dwilliams
    #1

    I have a subdirs projects that has a number of nested project files.

    Main.pro
      MY_VAR=1
      MY_SPACES=""
      include(mod1.pri.export)
      message("$$MYSPACES $$MY_VAR some message")
    
    mod1.pri.export
      MY_VAR +=1
      MY_SPACES="$$MY_SPACES  "
      include(mod2.pri.export)
      message("$$MYSPACES $$MY_VAR some other message")
    
    mod2.pri.export
      MY_VAR += 1
      MY_SPACES="$$MY_SPACES  "
      include(mod3.pri.export)
      message("$$MYSPACES $$MY_VAR yet another message")
    
    This nesting works very well in keeping the library and includ paths easy to maintain.  But, it is a little hard to see where messages are coming.  It looks like this:
    
    Project MESSAGE: 1 some message
    Project MESSAGE: 1 some other message
    Project MESSAGE: 1 yet another message
    
    I would like it to look more like the following
    
    Project MESSAGE: 1 some message
    Project MESSAGE:    2 some other message
    Project MESSAGE:       3 yet another message
    

    I can successfully pass the variable. But, I don't know how to increment it by 1 nor add spaces to the other.

    Do you have any suggestions.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      Your example with messages adjusted to deliberately show which is which, and the typo "MYSPACES" corrected, outputs this for me:

      chrisw@newton:/tmp/tt$ qmake
      Project MESSAGE:        1 1 1 1 from mod3
      Project MESSAGE:        1 1 1 1 from mod2
      Project MESSAGE:        1 1 1 1 from mod1
      Project MESSAGE:        1 1 1 1 some message
      

      It is a single compound PRO file not a subdirs project. The file is effectively:

      MY_VAR=1
      MY_SPACES=""
      # include(mod1.pri.export)
        MY_VAR +=1
        MY_SPACES="$$MY_SPACES  " 
        # include(mod2.pri.export)
          MY_VAR +=1
          MY_SPACES="$$MY_SPACES  "
          # include(mod3.pri.export)
            MY_VAR += 1
            MY_SPACES="$$MY_SPACES  "
            message("$$MY_SPACES $$MY_VAR from mod3")
          message("$$MY_SPACES $$MY_VAR from mod2")
        message("$$MY_SPACES $$MY_VAR from mod1")
      message("$$MY_SPACES $$MY_VAR some message")
      

      There is no arithmetic ability in qmake. This:

      MY_VAR +=1
      

      adds another string "1" to the list in MY_VAR. This all happens when parsing the PRO file, and the final MY_VAR value is what makes it into the variable expansions in the message() calls.

      If your project was a subdirs project then $$PRO_FILE and/or $$PWD could be used in the messages to identify where they come from.

      1 Reply Last reply
      2
      • D Offline
        D Offline
        dwilliams
        wrote on last edited by
        #3

        Thank you! Your explanation cleared that up very well and I better understand how qmake variables work.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dwilliams
          wrote on last edited by
          #4

          My goal was to create a project display so it's easy to determine where a problem occurs when updating the project files. I have several libraries and the dependencies can be nest quite a bit. I wanted output like:

          Project MESSAGE  Project.Pro
          Project MESSAGE    include file 1
          Project MESSAGE      include file 2
          Project MESSAGE        include file 3
          Project MESSAGE        include file 3 -- done
          Project MESSAGE      include file 2 -- done
          Project MESSAGE    include file 1 -- done
          Project MESSAGE  Project.pro -- done
          

          To accomplish that I did the following pattern

          Project.pro
              INDENT_SPACES = ""
              INDENT_ADD_SPACES = "  "
              message("$$INDENT_SPACESProject.pro")
             FILE_NAME = include1.pri.export
             !exists($$FILE_NAME) {
                 message("$${INDENT_SPACES}File does not exist: $$FILE_NAME")
                 error()
             }
             ! include(FILE_NAME) {
                 message("$${INDENT_SPACES}Error importing file: $$FILE_NAME")
                       error()
            }
              message("$$INDENT_SPACESProject.pro" -- done)
          
          include1.pri.export
              UNIQUE_VARIABLE = $$INDENT_SPACES
              INDENT_SPACES += INDENT_ADD_SPACES
              message("$${INDENT_SPACESinclude file 1"}
              # Follow the pattern described in Project.Pro to import file include2.pri.export
              message("$${INDENT_SPACESinclude file 1 -- done"}
              INDENT_SPACES = $$UNIQUE_VARIABLE
          
          include2.pri.export
              UNIQUE_VARIABLE2 = $$INDENT_SPACES
              INDENT_SPACES += INDENT_ADD_SPACES
              message("$${INDENT_SPACESinclude file 2"}
              # Follow the pattern described in Project.Pro to import file includ3.pri.export
              message("$${INDENT_SPACESinclude file 2 -- done"}
              INDENT_SPACES = $$UNIQUE_VARIABLE2
          
          include2.pri.export
              UNIQUE_VARIABLE3 = $$INDENT_SPACES
              INDENT_SPACES += INDENT_ADD_SPACES
              message("$${INDENT_SPACESinclude file 3"}
              # Follow the pattern described in Project.Pro to import file includ3.pri.export
              message("$${INDENT_SPACESinclude file 3 -- done"}
              INDENT_SPACES = $$UNIQUE_VARIABLE3
          

          I hope it helps!

          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