Results 1 to 6 of 6

Thread: Shared/Global/Inherited Variables between projects

  1. #1
    Join Date
    Dec 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Shared/Global/Inherited Variables between projects

    Hi,
    My question is, if there is a way to declare a variable in a PRO file, so it is visible in all subproject?
    I have a project that has different build options, where different flags to the compiler are passed. I want to have a base PRO file for each of the different builds and in these PRO files to define the different flags.
    The horrible alternative is to create different versions of every subproject.
    I am also aware that I can pass to QMake a variable that defines which build to execute, but in Qt Creator those are kept in the .user file, which is not under version control and is not share amongst developers.

  2. #2
    Join Date
    Oct 2009
    Posts
    483
    Thanked 96 Times in 93 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Shared/Global/Inherited Variables between projects

    The way I do this is that I put the parts common to all subprojects in a .pri file, say common.pri, which I include from each subproject's .pro file using include(path/to/common.pri) (say include(../common.pri) if your subprojects are in subdirectories of the directory containing common.pri).

    Then you can set global flags in common.pri that will affect the build process in each subproject (e.g. debug vs release, custom CONFIG variables, etc.).

  3. #3
    Join Date
    Dec 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Shared/Global/Inherited Variables between projects

    Quote Originally Posted by yeye_olive View Post
    The way I do this is that I put the parts common to all subprojects in a .pri file, say common.pri, which I include from each subproject's .pro file using include(path/to/common.pri) (say include(../common.pri) if your subprojects are in subdirectories of the directory containing common.pri).

    Then you can set global flags in common.pri that will affect the build process in each subproject (e.g. debug vs release, custom CONFIG variables, etc.).
    Thank you for your reply, but in this scenario how are you going to choose between, let's say, build_option_1, build_option_2 and build_option_3?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,355
    Thanks
    3
    Thanked 5,009 Times in 4,788 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: Shared/Global/Inherited Variables between projects

    You add CONFIG += build_option_1 (or equivalent) to the project file you want to build with option 1.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Shared/Global/Inherited Variables between projects

    Hi

    I have the following *.pro files :

    Qt Code:
    1. # head - pro file :
    2. TEMPLATE = subdirs
    3. CONFIG = qt thread ordered
    4.  
    5. # save root directory
    6. PROJECT_ROOT_DIRECTORY = $$_PRO_FILE_PWD_
    7. message("Master pro file path : ["$${PROJECT_ROOT_DIRECTORY}"]") // output : "Master pro file path : [/Path/To/Directory]"
    8.  
    9. # project subdirs
    10. SUBDIRS += PROJECT1
    To copy to clipboard, switch view to plain text mode 

    and

    Qt Code:
    1. # PROJECT1 - pro file :
    2. TEMPLATE = app
    3.  
    4. # etc.
    5.  
    6. # output 'PROJECT_ROOT_DIRECTORY ' contents
    7. message("Master pro file path : "$${PROJECT_ROOT_DIRECTORY}) // output : "Master pro file path : []"
    To copy to clipboard, switch view to plain text mode 

    How do I pass variables between the 2 pro files (here the variable is PROJECT_ROOT_DIRECTORY) ?

  6. #6

    Default Re: Shared/Global/Inherited Variables between projects

    How did you solve it in the end?

Similar Threads

  1. QDevelop - global variables & help
    By impeteperry in forum Qt-based Software
    Replies: 2
    Last Post: 10th June 2011, 00:28
  2. Using Singletton Pattern for global variables
    By harmodrew in forum Newbie
    Replies: 6
    Last Post: 7th August 2010, 10:37
  3. Qt and global variables
    By Morea in forum Qt Programming
    Replies: 11
    Last Post: 2nd February 2007, 00:42
  4. Global variables
    By Mariane in forum Newbie
    Replies: 14
    Last Post: 10th October 2006, 18:23
  5. declaration of global variables???
    By pranav_kavi in forum Newbie
    Replies: 6
    Last Post: 31st January 2006, 20:56

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.