Qt medium pro.pri configuration details

Pro is the project file of qmake, and i in pri file is the initial letter of include. It is similar to the header file in C and C + +, that is, we can Part of the pro file is placed in a separate file Pri file, and then included. Using include in the project file of each project is similar to including the header file. In this way, the PRI file can be included in the project, which eliminates the need to set duplicate public variables in each subproject.

For the variable configuration in Qt project file, you can see the variable variable manual in Qt help document, as shown below

The following configuration values control compilation flags:

optionexplain
releaseThe project is built in release mode. If debug is also specified, the last one takes effect.
debugThe project is built in debug mode.
debug_and_releaseThe project is prepared to be built in two modes: debug and release.
debug_and_release_targetThis option is set by default. If debug is also specified_ and_ Release, the final debug and release are built in different directories.
build_allIf debug is specified_ and_ Release. By default, the project will be built in debug and release modes.
autogen_precompile_sourceAutomatically generate a cpp file, contained in The precompiled header file specified in pro.
orderedWhen using subdirs templates, this option specifies that they should be processed in the order of the directory list.
precompile_headerSupport for precompiled header files can be used in projects.
warn_onThe compiler should output as many warnings as possible. If warn is also specified_ Off, the last one takes effect.
warn_offThe compiler should output as few warnings as possible.
exceptionsEnable exception support. Default settings.
exceptions_offDisable exception support.
rttiEnable RTTI support. By default, the compiler default is used.
rtti_offDisable RTTI support. By default, the compiler default is used.
stlEnable STL support. By default, the compiler default is used.
stl_offDisable STL support. By default, the compiler default is used.
threadEnable thread support. Enabled when CONFIG includes qt, which is the default setting.
c++11Enable c++11 support. If the compiler does not support c++11, it has no effect. Support is disabled by default.
c++14Enable c++14 support. If the compiler does not support c++14, it has no effect. By default, support is disabled.

When the debug and release options are used (the default in Windows), the project will be processed three times: one "meta" Makefile will be generated once, and the other two will be generated Debug and Makefile Release.

In the following times, build_pass and the corresponding debug or release are added to the CONFIG option. This allows it to perform build specific tasks.
For example:

build_pass:CONFIG(debug, debug|release) {
    unix: TARGET = $$join(TARGET,,,_debug)
    else: TARGET = $$join(TARGET,,,d)
}

DEFINES += USE_MY_STUFF

You can then use it in your code:

#ifdef USE_MY_STUFF
    // TODO
#else
    // TODO
#endif

You can often specify the special version of the project (such as official version and trial version), and restrict some special function modules (such as dongle).

DEPENDPATH += . forms include qrc sources

DESTDIR = ../../lib

FORMS = mydialog.ui \
        mywidget.ui \
        myconfig.ui

HEADERS = myclass.h \
          login.h \
          mainwindow.h

INCLUDEPATH = c:/msdev/include d:/stl/include

If the path contains spaces, you need to use quotation marks.

win32:INCLUDEPATH += "C:/mylibs/extra headers"
unix:INCLUDEPATH += "/home/user/extra headers"

win32:LIBS += c:/mylibs/math.lib
unix:LIBS += -L/usr/local/lib -lmath

If the path contains spaces, you need to include the path in quotation marks.

win32:LIBS += "C:/mylibs/extra libs/extra.lib"
unix:LIBS += "-L/home/user/extra libs" -lextra

unix:MOC_DIR = ../myproject/tmp
win32:MOC_DIR = c:/myproject/tmp

unix:OBJECTS_DIR = ../myproject/tmp
win32:OBJECTS_DIR = c:/myproject/tmp

QT -= gui # Use only core modules

If you want to create an interface that uses XML and network related classes, you need to include the following modules:

QT += core gui widgets xml network

If your project is a Qt Designer plug-in, use the value uiplugin to specify that the project is built into a library, but the specific Qt Designer plug-in supports, please refer to: building and installing the plug in.

unix:RCC_DIR = ../myproject/resources
win32:RCC_DIR = c:/myproject/resources

RESOURCES += Resource/resource.qrc

RC_FILE += myapp.rc

RC_ICONS = myapp.ico  

SOURCES = myclass.cpp \
          login.cpp \
          mainwindow.cpp

TEMPLATE = app
TARGET = myapp
SOURCES = main.cpp

The above project will generate an executable file, which is myapp. Com under Windows Exe, myapp under Unix.

optionexplain
appCreate a Makefile for building applications (default).
libCreate a Makefile to build the library.
subdirsCreate a Makefile to build the target subdirectory, which is specified using the subdir variable.
auxCreate a Makefile that doesn't build anything. If no compiler needs to be called to create a target, such as your project written in an interpreted language, use this function. Note: This template type can only be used for Makefile based generators. In particular, it will not work in vcxproj and Xcode generators.
vcappWindows only. Create a Visual Studio application project.
vclibWindows only. Create a Visual Studio library project.

For example:

TEMPLATE = lib
SOURCES = main.cpp
TARGET = mylib

TRANSLATIONS += Resource/myapp_zh.ts \
                Resource/myapp_en.ts

unix:UI_DIR = ../myproject/ui
win32:UI_DIR = c:/myproject/ui

The reference article link of parameter configuration details is as follows: Detailed explanation of pro configuration of Qt , you can pay attention to this blogger. His writing is very good.
If I have time, I will share the more complex use of pri.

Keywords: Qt

Added by metrathon on Tue, 25 Jan 2022 04:40:11 +0200