View Full Version : Equivalent of #define in .pro file
sattu
11th April 2014, 13:09
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-
#define shapeA
#if defined(shapeA)
FORMS += \
formA.ui
#elif defined(shapeB)
FORMS += \
formB.ui
#endif
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
stampede
11th April 2014, 13:45
// .pro
DEFINES += SHAPE_A
#...
contains(DEFINES,SHAPE_A){
FORMS += formA.ui
}
contains(DEFINES,SHAPE_B){
FORMS += formB.ui
}
anda_skoa
11th April 2014, 13:52
You can do all kinds of conditions, e.g. based on CONFIG http://qt-project.org/doc/qt-4.8/qmake-advanced-usage.html#configuration-and-scopes
Cheers,
_
sattu
11th April 2014, 14:45
// .pro
DEFINES += SHAPE_A
#...
contains(DEFINES,SHAPE_A){
FORMS += formA.ui
}
contains(DEFINES,SHAPE_B){
FORMS += formB.ui
}
Hi Stampede, following your method I modified my .pro file. Now my .pro file is-
DEFINES += SHAPE_A
QT += core gui
TARGET = Test
TEMPLATE = app
HEADERS += \
testa.h
SOURCES += \
testa.cpp \
main.cpp
contains(DEFINES,SHAPE_A)
{
FORMS += \
form.ui
}
contains(DEFINES,SHAPE_B)
{
FORMS += \
ShapeB/form.ui
}
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:
You can do all kinds of conditions, e.g. based on CONFIG http://qt-project.org/doc/qt-4.8/qmake-advanced-usage.html#configuration-and-scopes
Cheers,
_
Thanks a lot anda_skoa. I followed your lead and it worked finally. Following is my .pro file-
CONFIG += SHAPE_A
#CONFIG += SHAPE_B
QT += core gui
TARGET = Test
TEMPLATE = app
HEADERS += \
testa.h
SOURCES += \
testa.cpp \
main.cpp
SHAPE_A{
FORMS += \
form.ui
}
SHAPE_B{
FORMS += \
ShapeB/form.ui
}
Once again, thanks a lot. Now I can include multiple gui files for a single class depending upon my size and shape requirements :)
stampede
11th April 2014, 14:47
Opening curly bracket must be on the same line with "contains()":
// wrong
contains(...)
{
// good
contains(...) {
I think its somewhere in the qmake docs.
sattu
11th April 2014, 16:02
Opening curly bracket must be on the same line with "contains()":
// wrong
contains(...)
{
// good
contains(...) {
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?
anda_skoa
11th April 2014, 17:47
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
sattu
14th April 2014, 06:50
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,
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.