I have been working on the Qt Project for some time, but I still have a general understanding of Qt. Recently I am going to refactor my project code. Therefore, continue to write this knowledge and record it!
Although each time we compare it with cmake, we always say that qmake is simple and has fewer functions. But qmake is still a very complicated thing. I think most people should be like me:
- It's not clear how CONFIG and other variables work.
- The number of used qmake built-in variables and functions cannot exceed 20
Check the *. pro file used in the Qt Creator source code, QtSolution, and other libraries, just like reading Tianshu.
This article only captures one line and briefly introduces four types of files, including *. pro, *. pri, *. prf, and *. Prolactin: what are they used? How are they used?
1. *. pro
Qmake project (ProObject) file, which must be very familiar to everyone. Then I will not bother. The example above:
This is the. pro File (propriprfprolactin. pro) of a typical Qt sample program ):
TEMPLATE = appCONFIG + = QTQT + = core guiTARGET = propriprfprlSOURCES + = main. cpp/widget. cppHEADERS + = widget. hFORMS + = widget. ui
- The first three rows are the default values of qmake.
- The TARGET line specifies the project name, which can be omitted.
II. *. pri
What is I? Include (INclude. Similar to the header files in C and C ++, we can put a part of the *. pro file into a *. pri file and include it.
In the preceding example, we separate the source file settings and place them in the propriprfprolactin. pri file:
SOURCES + = main. cpp/widget. cppHEADERS + = widget. hFORMS + = widget. ui
In this case, the propriprfprolactin. pro file can be simplified:
TEMPLATE = appCONFIG + = QTQT + = core guiTARGET = propriprfprlinclude (propriprfprolactin. pri)
- How can this be used? For our example, it is useless. Instead, it is more troublesome to add a file.
- However, if a large project contains multiple *. pro files, these pro files need some common settings or files. This is necessary.
III. *. prf
F is another magic horse? Feature (FEature) first character
- Similar to the pri file, this file is also included in the pro file
- But: it is more concealed.
- You often deal with it, but you may always turn a blind eye to it.
We have actually used this in this example.
CONFIG + = QT
When we specify an item in CONFIG, qmake will try to load the corresponding feature file:
- Mkspecs/features/Qt. prf in the qt installation directory
- The file name of the features file must be in lowercase.
- In which directories does qmake search for features files?
- Manual is described here.
- You only need to know the $ QTDIR/mkspecs/features mentioned above.
Write your own features File: propriprfprolactin. prf
Win32: CONFIG + = console
- Adding a console to a win32 program is a bit of a breeze.
- Place the file in the directory we mentioned earlier
Then add
CONFIG + = propriprfprolactin
I can see the same effect as CONFIG + = console?
Note: We can also use the load command to load the prf file. For example, the preceding command can be considered as equivalent
Load (propriprfprolactin)
V. *. Prolactin
L This is easy to understand. Link (LInk. Generation and usage of static libraries are closely related (this file can also be found in the dynamic library, go to the lib directory under the Qt installation directory to see ).
- When generating a static library, we need to use the following configuration (and then generate the *. Prolactin file with the same name as the library file)
CONFIG + = create_prolactin
- When the TEMPLATE of the project is app, the following command is automatically added (when the library file is searched, the corresponding *. Prolactin file is searched)
CONFIG + = link_pri
So what is the purpose of this file? For example, the library QextSerialPort1.2, which may be familiar to you (in windows ):
If there is a prolactin file, the file will contain the dependency information. Let's take a look:
QMAKE_PRL_BUILD_DIR = E: // dbzhang800-qextserialport/buildlibQMAKE_PRO_INPUT = buildlib. protocol = qextserialport-1.2QMAKE_PRL_CONFIG = cipher lex yacc warn_on uic resources cipher windows release build Release build_pass qt warn_on release incremental flat link_prolactin precompile_header contains cipher character when using stl exceptions rtti mmx 3 dnow sse sse2 ReleaseBuild release build_pass qt qextserialport-buildlib create_prolactin qextserialport-uselib qextserialport-static variable build_all release build ReleaseBuild Release build_pass no_autoqmake staticlib static moc variable = setupapi. lib advapi32.lib user32.lib d: // Qt // 4.7.0 // lib // QtGui4.lib d: // Qt // 4.7.0 // lib // QtCore4.lib
Introduction to qmake pro, pri, prf, and prolactin files