Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting values from pro files in Qt

Tags:

qt

qt4

qmake

I am using Qt 4.5 in Windows XP. My pro file has the variable VERSION = 1.0. Now i need to read this variable and get its value (1.0) from the source code. So that I don't have to maintain another variable for version inside my source code. I just read from the pro file and update it. So that the value remains consistent all over my project. Is it possible? Any pointers regarding this are welcome..

like image 683
liaK Avatar asked May 12 '10 07:05

liaK


People also ask

What is Pro file in Qt?

pro file is to list the source files that are involved in a project. Since qmake is used for building Qt and its associated tools, it knows Qt very well and can generate rules for invoking moc, uic, and rcc. As a result, the syntax is very concise and easy to learn.

What pro and PRI file in Qt?

pri files is exactly the same as the format of the . pro files. The main difference is one of intent; a . pro is what most people would expect to run qmake on directly, while a .

What is PWD in Qt?

$$PWD means the dir where the current file (. pro or . pri) is. It means the same in LIBS .


2 Answers

Use somethings like this:

DEFINES += VERSION=\\\"$$VERSION\\\"

This will define a macro that you can use in C source code. Get rid of the backslashes and quotes if you want a number, not a string.

like image 98
Lukáš Lalinský Avatar answered Oct 03 '22 07:10

Lukáš Lalinský


I'll elaborate on this a bit.

In the YourApp.pro:

VERSION = 0.0.0.1
DEFINES += APP_VERSION=\\\"$$VERSION\\\"

In the main.cpp:

#include <QApplication>
QCoreApplication::setApplicationVersion(QString(APP_VERSION));

Wherever else in your sources, e.g. in the imaginary controller.cpp:

#include <QApplication>
QString yourAppVersion = QCoreApplication::applicationVersion();
like image 30
Neurotransmitter Avatar answered Oct 03 '22 07:10

Neurotransmitter