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

下面是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:

 


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)
      }
   }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值