• qt模块feature QT_FEATURE_* qt_lib_*.pri QT_CONFG qtConfig


    qt为方便对功能和代码进行删减和系统兼容,将代码拆分成很多模块且对每个模块梳理出feature,为了简化程序的使用和其他目的,一个模块编译成一个单独的dll,qt还对每个模块的头文件分成public部分和private部分。在编译模块前,通过修改模块对应源码文件夹下的confiure.json控制feature开关来删减系统不支持或者不必要的feature,对应feature的condition是可配置的,感兴趣的可以查看qt的编译脚本文件(shell脚本/dos脚本)。

    widgets/configure.json

    在配置好模块的configure.json后,运行configure启动编译脚本(shell脚本/dos脚本),过程中会自动为模块生成对应头文件,比如widgets 模块,会生成qtwidgets-config.h和qtwidgets-config-p.h,每一个属性在.h中都有一个宏,作为代码的宏开关,值一般为1或-1,用于控制模块源码的逻辑,其内容如下:

    qtwidgets-config.h


    在qt 的源文件qglobal.h中有这样两个方便使用feature对应宏开关的宏定义QT_CONFIGQT_REQUIRE_CONFIG

    1. //QtInstallDir\Qt5.12.0\5.12.0\msvc2015_64\include\QtCore\qglobal.h
    2. #define QT_CONFIG(feature) (1/QT_FEATURE_##feature == 1)
    3. #define QT_REQUIRE_CONFIG(feature) Q_STATIC_ASSERT_X(QT_FEATURE_##feature == 1, "Required feature " #feature " for file " __FILE__ " not available.")
    qmainwindow.h

    qt模块编译好后会产生对应qt_lib_*.pri和qt_lib_*_private.pri脚本(qmake language脚本)文件,方便qmake生成makefile时查询模块是否支持对应的feature。下面是qt_lib_core.pri文件内容:

    1. #D:\Qt\Qt5.12.0\5.12.0\msvc2015_64\mkspecs\modules\qt_lib_core.pri
    2. QT.core.VERSION = 5.12.0
    3. QT.core.name = QtCore
    4. QT.core.module = Qt5Core
    5. QT.core.libs = $$QT_MODULE_LIB_BASE
    6. QT.core.includes = $$QT_MODULE_INCLUDE_BASE $$QT_MODULE_INCLUDE_BASE/QtCore
    7. QT.core.frameworks =
    8. QT.core.bins = $$QT_MODULE_BIN_BASE
    9. QT.core.depends =
    10. QT.core.uses = libatomic
    11. QT.core.module_config = v2
    12. QT.core.CONFIG = moc resources
    13. QT.core.DEFINES = QT_CORE_LIB
    14. QT.core.enabled_features = properties animation textcodec big_codecs codecs commandlineparser cxx11_future textdate datestring filesystemiterator filesystemwatcher gestures itemmodel proxymodel identityproxymodel library mimetype processenvironment process statemachine qeventtransition regularexpression settings sharedmemory sortfilterproxymodel std-atomic64 stringlistmodel systemsemaphore temporaryfile timezone topleveldomain translation xmlstream xmlstreamreader xmlstreamwriter
    15. QT.core.disabled_features =
    16. QT_CONFIG += properties animation textcodec big_codecs codecs textdate datestring doubleconversion filesystemiterator filesystemwatcher gestures itemmodel proxymodel identityproxymodel library mimetype process statemachine regularexpression settings sharedmemory sortfilterproxymodel stringlistmodel systemsemaphore temporaryfile translation xmlstream xmlstreamreader xmlstreamwriter
    17. QT_MODULES += core

    里面的QT.core.enabled_features项描述了core模块所支持的特性,所有的features是在编译模块源码之前,事先配置对应模块(module)源码文件夹下的configure.json文件内容的执行结果。qt_lib_*.pri只是提供一个方便脚本(qmake language脚本)快速查询的结果的功能。对比可以发现,qt_lib_*.pri中的enable_features项与qt*-config.h中的项基本一一对应。
    脚本查询的入口参考:qtConfig(inputdialog) 

    qtConfig()查询的是模块中的enabled_features值,这个脚本中的QT_CONFIG暂时没有发现有什么用。

    QT_CONFIG宏用法及支持的参数_荆楚闲人的博客-CSDN博客_qtconfig

     qt 私有头文件 private_丘上人的博客-CSDN博客 

    qmake language qt 工程文件 配置文件 .pro .prl .prf .pri 词法 语法 for循环 判断语句 函数定义_丘上人的博客-CSDN博客

  • 相关阅读:
    C#编程题分享(1)
    ElasticSearch第四讲:ES详解:ElasticSearch和Kibana安装
    K8S:Pod容器中的存储方式及PV、PVC
    中文Stable Diffusion模型太乙使用教程
    1. 爬虫之Beautifulsoup解析库&在线解析图片验证码
    机器学习的医疗乳腺癌数据的乳腺癌疾病预测
    数据结构和算法训练:第二十五弹
    Docker
    报表控件FastReport与StimulSoft功能对比
    Redis与Mybatis
  • 原文地址:https://blog.csdn.net/qiushangren/article/details/128177654