QT pro file analysis

Use qmake in QT to automatically generate pro files. If you want to customize the project options yourself, you need to modify the pro files yourself.

The pro file has the following keywords: TEMPLATE, TARGET, DESTDIR, DEPENDPATH, INCLUDEPATH, SOURCES, HEADERS, FORMS, LIBS, TRASHLATIONS, RESOURCES, CONFIG, UI_DIR, RCC_DIR, MOC_DIR, OBJECTS_DIR, DEFINES.

Among them: The TEMPLATE variable defines the compilation mode of the project, which is compiled as app by default. TEMPLATE can be: app, lib (library), subdirs (multi-level directory management), etc.

TARGET: The name of the generated target. Such as: TARGET = mylib

DESTDIR: The path to the generated target. For example: DESTDIR = ../bin/ The path of the target file is the bin directory one level above the directory where the current pro file is located

DEPENDPATH: The dependency path of the project

INCLUDEPATH: Specifies the header file path to be used by the project, generally including the user-defined header file path or the header file path that is not placed in the system header file path

SOURCES: source files required by the project

HEADERS: The header files required by the project, generally including user-defined header files or header files not placed in the system header file path

FORMS: The ui file used by the project (the ui file is generated by the QT designer)

LIBS: Load dynamic library files. Such as: LIBS+=./mitab/libmitab.so

TRASHLATIONS: Load the language translation *.ts file to be used

RESOURCES: Load the resource *.qrc file to be used

CONFIG: Tell qmake the configuration information of the application: this variable can be used to specify whether to generate debug mode or release mode, or both; it can also be used to turn on compiler warnings (warn_on outputs as many warnings as possible) or turn off ( warn_off - the compiler will output as little warning information as possible); it can also be used to configure the library to be loaded by Qt, for example, if you want to use Qt's multi-threading, then: CONFIG+=qt thread Then configure debug or release mode for example:

CONFIG +=debug_and_release
CONFIG(debug,debug|release){
TARGET= hello
DESTDIR= ./debug
}else{
TARGET= hello
DESTDIR= ./release
}

If you want to run the console under windows: CONFIG +=console

UI_DIR: UIC converts ui into the directory where the header files are stored

RCC_DIR: RCC converts the qrc file to the directory where the header file is stored;

MOC_DIR: The MOC command converts the header file containing Q_OBJECT into the directory where the standard header file is stored;

OBJECTS_DIR: The directory where the generated object files are stored;

DEFINES: A list of additional preprocessor definitions required by the application # can be used in the .h file: #ifdefinexx_xx_xxx;

LIBS += -L folderPath //The path of the imported lib file -L: import path

Release:LIBS+= -L folderPath // lib file path introduced by release version

Debug:LIBS+= -L folderPath // lib file path introduced by Debug version

RC_FILE = xxx.icns //Resource files such as pictures used in the program;

QT is cross-platform, so we use the same pro file on different platforms, which needs to add information about the platform. Windows platform is win32, Linux platform is unix.
For example, the dynamic library file formats in Windows and Linux are different, one is a lib file and the other is a so file: win32:LIBS+= ./mitab/mitab_i.lib unix:LiBS+= ./mitab/libmitab.so
Another example:
win32 {
SOURCES+= hello_win.cpp //win platform
}
unix{
SOURCES+= hello_linux.cpp //unix/linux platform
}

可以通过在其它任何一个变量的变量名前加$$来把这个变量的值分配给当前的变量,例如:MY_DEFINES= $$DEFINE #将DEFINE的值分配给MY_DEFINES
又如:
TARGET = myapp
UI_DIR = ../bin/$$TARGET/ui
MOC_DIR = ../bin/$$TARGET/moc
OBJECTS_DIR = ../bin/$$TARGET/objects

The files generated by uic are in the ../bin/myapp/ui directory; the moc files are in the ../bin/myapp/moc directory; the obj object files are in the ../bin/myapp/objects directory.

Original address: https://www.cnblogs.com/boright88/p/6264642.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324853727&siteId=291194637