Results 1 to 8 of 8

Thread: Equivalent of #define in .pro file

  1. #1
    Join Date
    Sep 2010
    Location
    Bangalore
    Posts
    169
    Thanks
    59
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Question Equivalent of #define in .pro file

    Hi everyone,

    I was wondering what's the equivalent of #define in my .pro file.
    For example, this is what I want to achieve in my .pro file-

    Qt Code:
    1. #define shapeA
    2.  
    3.  
    4. #if defined(shapeA)
    5. FORMS += \
    6. formA.ui
    7. #elif defined(shapeB)
    8. FORMS += \
    9. formB.ui
    10. #endif
    To copy to clipboard, switch view to plain text mode 

    I know # symbol is meant to comment a line in .pro file, I just used it for illustration purpose.
    And yes, I did search in google about this. I get some examples regarding the use of CONFIG+= or DEFINES+= . I tried them in my .pro file but couldn't achieve what I wanted to. I would be really glad if someone would help me out regarding this.


    -Thanks,
    sattu

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Equivalent of #define in .pro file

    Qt Code:
    1. // .pro
    2.  
    3. DEFINES += SHAPE_A
    4.  
    5. #...
    6.  
    7. contains(DEFINES,SHAPE_A){
    8. FORMS += formA.ui
    9. }
    10. contains(DEFINES,SHAPE_B){
    11. FORMS += formB.ui
    12. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to stampede for this useful post:

    sattu (11th April 2014)

  4. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Equivalent of #define in .pro file

    You can do all kinds of conditions, e.g. based on CONFIG http://qt-project.org/doc/qt-4.8/qma...ion-and-scopes

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    sattu (11th April 2014)

  6. #4
    Join Date
    Sep 2010
    Location
    Bangalore
    Posts
    169
    Thanks
    59
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Equivalent of #define in .pro file

    Quote Originally Posted by stampede View Post
    Qt Code:
    1. // .pro
    2.  
    3. DEFINES += SHAPE_A
    4.  
    5. #...
    6.  
    7. contains(DEFINES,SHAPE_A){
    8. FORMS += formA.ui
    9. }
    10. contains(DEFINES,SHAPE_B){
    11. FORMS += formB.ui
    12. }
    To copy to clipboard, switch view to plain text mode 
    Hi Stampede, following your method I modified my .pro file. Now my .pro file is-
    Qt Code:
    1. DEFINES += SHAPE_A
    2.  
    3.  
    4. QT += core gui
    5.  
    6. TARGET = Test
    7. TEMPLATE = app
    8.  
    9. HEADERS += \
    10. testa.h
    11.  
    12. SOURCES += \
    13. testa.cpp \
    14. main.cpp
    15.  
    16. contains(DEFINES,SHAPE_A)
    17. {
    18. FORMS += \
    19. form.ui
    20. }
    21.  
    22. contains(DEFINES,SHAPE_B)
    23. {
    24. FORMS += \
    25. ShapeB/form.ui
    26. }
    To copy to clipboard, switch view to plain text mode 

    The problem is it always takes ShapeB/form.ui inspite of SHAPE_B not being defined. Can you point out what I am doing wrong?


    Added after 8 minutes:


    Quote Originally Posted by anda_skoa View Post
    You can do all kinds of conditions, e.g. based on CONFIG http://qt-project.org/doc/qt-4.8/qma...ion-and-scopes

    Cheers,
    _
    Thanks a lot anda_skoa. I followed your lead and it worked finally. Following is my .pro file-
    Qt Code:
    1. CONFIG += SHAPE_A
    2. #CONFIG += SHAPE_B
    3.  
    4. QT += core gui
    5.  
    6. TARGET = Test
    7. TEMPLATE = app
    8.  
    9. HEADERS += \
    10. testa.h
    11.  
    12. SOURCES += \
    13. testa.cpp \
    14. main.cpp
    15.  
    16. SHAPE_A{
    17. FORMS += \
    18. form.ui
    19. }
    20. SHAPE_B{
    21. FORMS += \
    22. ShapeB/form.ui
    23. }
    To copy to clipboard, switch view to plain text mode 

    Once again, thanks a lot. Now I can include multiple gui files for a single class depending upon my size and shape requirements
    Last edited by sattu; 11th April 2014 at 13:45.

  7. #5
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Equivalent of #define in .pro file

    Opening curly bracket must be on the same line with "contains()":
    Qt Code:
    1. // wrong
    2. contains(...)
    3. {
    4.  
    5. // good
    6. contains(...) {
    To copy to clipboard, switch view to plain text mode 
    I think its somewhere in the qmake docs.

  8. The following user says thank you to stampede for this useful post:

    sattu (11th April 2014)

  9. #6
    Join Date
    Sep 2010
    Location
    Bangalore
    Posts
    169
    Thanks
    59
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Equivalent of #define in .pro file

    Quote Originally Posted by stampede View Post
    Opening curly bracket must be on the same line with "contains()":
    Qt Code:
    1. // wrong
    2. contains(...)
    3. {
    4.  
    5. // good
    6. contains(...) {
    To copy to clipboard, switch view to plain text mode 
    I think its somewhere in the qmake docs.
    Awesome, thanks a lot. It's amazing to see that sometimes even the placement of brackets play such a big role


    Added after 11 minutes:


    Stampede and Anda_skoa,
    one more doubt. I am able to fulfill my objective using both DEFINES and CONFIG. Then what's the difference between both of them?
    Last edited by sattu; 11th April 2014 at 15:02.

  10. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Equivalent of #define in .pro file

    DEFINES are things that get "exported" to C++, i.e. they become compiler -D items and can therefore be handled with #ifdef in code.

    If you don't need that I would suggest using CONFIG and keep those unnecessary defines from the compiler invocations.

    Cheers,
    _

    P.S.: you can also use the contains() syntax with CONFIG if you prefer it over the other condition syntax

  11. The following user says thank you to anda_skoa for this useful post:

    sattu (14th April 2014)

  12. #8
    Join Date
    Sep 2010
    Location
    Bangalore
    Posts
    169
    Thanks
    59
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Equivalent of #define in .pro file

    Quote Originally Posted by anda_skoa View Post
    DEFINES are things that get "exported" to C++, i.e. they become compiler -D items and can therefore be handled with #ifdef in code.

    If you don't need that I would suggest using CONFIG and keep those unnecessary defines from the compiler invocations.

    Cheers,
    _

    P.S.: you can also use the contains() syntax with CONFIG if you prefer it over the other condition syntax
    That clears all my doubt. Now I can decide if I want to use DEFINES or CONFIG in my .pro file. Thanks a lot,

Similar Threads

  1. How to tranlaste #define and text from file
    By stevocz in forum Qt Programming
    Replies: 24
    Last Post: 18th December 2013, 08:06
  2. How to define a string marco in pro file
    By jevonwang in forum Qt for Embedded and Mobile
    Replies: 5
    Last Post: 6th May 2013, 05:49
  3. QMake how to define install target of lib in the .pro file
    By thgis in forum Qt Tools
    Replies: 1
    Last Post: 15th April 2013, 12:59
  4. How to define a string in a .pro file
    By ChristineD in forum Newbie
    Replies: 4
    Last Post: 16th October 2012, 17:14
  5. qmake rc file define version
    By cafu1007 in forum Qt Programming
    Replies: 3
    Last Post: 26th January 2012, 16:38

Tags for this Thread

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.