qmake生成的pro文件中QT变量的说明

版权声明

请尊重原创作品。转载请保持文章完整性,并以超链接形式注明原始作者“tingsking18”和主站点地址,方便其他朋友提问和指正。

下面是QT Assistant中关于QT变量的说明:

If the CONFIG variable contains the qt value, qmake's support for Qt applications is enabled. This makes it possible to fine-tune which of the Qt modules are used by your application. This is achieved with the QT variable which can be used to declare the required extension modules. For example, we can enable the XML and network modules in the following way:
CONFIG += qt
QT += network xml
Note that QT includes the core and gui modules by default, so the above declaration adds the network and XML modules to this default list. The following assignment omits the default modules, and will lead to errors when the application's source code is being compiled:
QT = network xml # This will omit the core and gui modules.
If you want to build a project without the gui module, you need to exclude it with the "-=" operator. By default, QT contains both core and gui, so the following line will result in a minimal Qt project being built:
QT -= gui # Only the core module is used.
The table below shows the options that can be used with the QT variable and the features that are associated with each of them:

qmake生成的pro文件中QT变量的说明


Note that adding the opengl option to the QT variable automatically causes the equivalent option to be added to the CONFIG variable. Therefore, for Qt applications, it is not necessary to add the opengl option to both CONFIG and QT.

我解释一下:QT缺省使用了core和gui库。我们在$QT/mkspecs/default/qmake.conf中可以看到有

QT+= core gui

这就是缺省为QT变量赋的值。

同样在$QT/mkspecs/win32-msvc/qmake.conf中也可以看到

QT+= core gui的定义。

当我们需要使用除core和gui之外的库的时候。我们就需要:

QT +=webkit类似这样的来使QT获取webkit的库。

我们来看$QT/mkspecs\features\qt.prf

# As order does matter for static libs, we reorder the QT variable here
TMPLIBS = webkit phonon dbus testlib script svg qt3support sql xmlpatterns xml opengl gui network core
for(QTLIB, $$list($$TMPLIBS)) {
contains(QT, $$QTLIB): QT_ORDERED += $$QTLIB
}

QT_UNKNOWN = $$QT
QT_UNKNOWN -= $$QT_ORDERED
QT = $$QT_ORDERED
for(QTLIB, $$list($$QT_UNKNOWN)) {
!contains(TMPLIBS, $$QTLIB):message("Warning: unknown QT: $$QTLIB")
}

这一段就是对QT这个变量进行重新赋值,如果我们使用的库在上述TMPLIBS定义的里面,就添加到QT变量中去。否则就warning

连接的时候需要lib文件,下面是对QTLIB进行的设置。

for(QTLIB, $$list($$lower($$unique(QT)))) {
unset(qlib_style)
!qt_debug:!qt_release {
CONFIG(debug, debug|release):qlib_style = debug
else:qlib_style = release
} else:CONFIG(qt_debug, qt_debug|qt_release) {
qlib_style = debug
} else {
qlib_style = release
}

unset(qlib)
isEqual(QTLIB, gui):qlib = QtGui
else:isEqual(QTLIB, network):qlib = QtNetwork
else:isEqual(QTLIB, xml):qlib = QtXml
else:isEqual(QTLIB, xmlpatterns):qlib = QtXmlPatterns
else:isEqual(QTLIB, opengl):qlib = QtOpenGL
else:isEqual(QTLIB, sql):qlib = QtSql
else:isEqual(QTLIB, core):qlib = QtCore
else:isEqual(QTLIB, canvas):qlib = QtCanvas
else:isEqual(QTLIB, qt3support):qlib = Qt3Support
else:isEqual(QTLIB, svg):qlib = QtSvg
else:isEqual(QTLIB, script):qlib = QtScript
else:isEqual(QTLIB, testlib):qlib = QtTest
else:isEqual(QTLIB, dbus):qlib = QtDBus
else:isEqual(QTLIB, phonon):qlib = phonon
else:isEqual(QTLIB, webkit):qlib = QtWebKit
else:message("Unknown QT: $$QTLIB"):qlib =
!isEmpty(qlib) {
target_qt:isEqual(TARGET, qlib) {
warning($$TARGET cannot have a QT of $$QTLIB)
} else {
DEFINES *= $$upper(QT_$${QTLIB}_LIB)
exists($$QMAKE_INCDIR_QT/$$qlib) {
INCLUDEPATH -= $$QMAKE_INCDIR_QT/$$qlib
INCLUDEPATH = $$QMAKE_INCDIR_QT/$$qlib $$INCLUDEPATH
}
isEqual(QTLIB, opengl):CONFIG += opengl
isEqual(QTLIB, qt3support):DEFINES *= QT3_SUPPORT
isEqual(QTLIB, testlib):CONFIG += console
isEqual(QTLIB, dbus):CONFIG += dbusadaptors dbusinterfaces

qtAddLibrary($$qlib)
}
}
}

你可能感兴趣的:(sql,xml,webkit,qt)