QT_QML_NO_CACHEGEN

禁用将 QML 文件编译为字节码或 C++ 代码的功能。

该变量在 Qt 6.8.1 中引入。

QT_QML_NO_CACHEGEN 这是一个 CMake 变量,可将其设置为禁用由qt_add_qml_module() 创建的 QML 目标中 QML 文件编译为字节码或 C++ 代码的功能。

其效果与设置qt_add_qml_module() 的NO_CACHEGEN 选项相同,但允许按目录或项目进行设置。

启用此选项可减少完成构建所需的构建步骤,从而缩短开发-调试的迭代周期。

为了最大限度地减小应用程序大小,请关闭此选项,转而使用QT_DISCARD_FILE_CONTENTS来删除嵌入到资源系统中的 QML 文件。

该变量可在项目的 CMakeLists.txt 中按以下方式设置:

set(QT_QML_NO_CACHEGEN TRUE)
qt_add_qml_module(MyModule
    URI MyModule
    VERSION 1.0
    ...
)

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.