Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QMake - How to add and use a variable into the .pro file

Tags:

qt

qmake

I have a qmake file generated by Qt creator. I am modifying it but I do not manage to understand how to create a variable.

For example, I want to declare the library MYPATH as I did here:

MYPATH = /lib/aaa/bbb unix:!macx:!symbian: LIBS += -L$(MYPATH) 

When I run qmake I find in the generated makefile

LIBS = ....... -L$(MYPATH) ..... 

But the MYPATH variable is not declared anywhere.

Does anyone know how to declare such a variable properly?

like image 875
Cristas Avatar asked Oct 13 '11 12:10

Cristas


People also ask

What is .pro file in QtCreator?

Project files contain all the information required by qmake to build your application, library, or plugin.

Where is .pro file in Qt?

Qt qmake Default "pro" file. If you start Qt Creator and select File -> New File or Project -> Application -> Qt Widgets application, Qt Creator will generate a project skeleton for you along with a "pro" file.

What is .PRI file in Qt?

This is usually called Project Include File.


2 Answers

QMake uses its own syntax for variable references.

  • VAR = foobar => Assign value to variable when qmake is run
  • $$VAR => QMake variable's value at the time qmake is run
  • $${VAR} => QMake variable's value at the time qmake is run (identical but enclosed to separate from surrounding text)
  • $(VAR) => Contents of an Environment variable at the time Makefile (not qmake) is run
  • $$(VAR) =>Contents of an Environment variable at the time qmake (not Makefile) is run

Try it like this

MYPATH = /lib/aaa/bbb unix:!macx:!symbian: LIBS += -L$${MYPATH} 
like image 134
jwernerny Avatar answered Oct 02 '22 23:10

jwernerny


Other useful variable type: $$[...] This means "configuration option that were set when Qt was built"

Example:

message($$[QT_INSTALL_BINS]) 

This gives:

C:\Qt\Qt5.0.2\5.0.2\msvc2010_opengl\bin 
like image 31
bocs Avatar answered Oct 02 '22 23:10

bocs