QT_QML_NO_QML_PREVIEW(全局属性)
控制是否为链接 Qt6::Qml 的可执行文件自动配置 qmlpreview 支持。
该变量自 Qt 6.12 起引入。
默认情况下,每个链接到Qt6::Qml 的可执行目标,在目标最终化时都会自动为其配置qmlpreview支持,就好像已对其显式调用了qt_add_qml_preview()一样。 那些本身由qt_add_qml_module()创建的 QML 模块的可执行目标不受此影响,因为它们已通过该命令获得了qmlpreview支持。
将此变量设置为真值将禁用所有目标的自动行为。 这将跳过为每个可执行文件创建预览目标时所花费的一小部分额外配置时间,对于不使用qmlpreview 的项目来说是值得的,例如仅通过QJSEngine 驱动 QML 进行脚本编写的应用程序,或者实时重载无关紧要的发布和 CI 构建。若完全不需要预览功能,可通过向 CMake 可执行文件传递
-DQT_QML_NO_QML_PREVIEW=ON参数传递给 cmake 可执行文件,或者如果永远不需要预览,则在项目的CMakeLists.txt 中进行设置。
若需更精细的控制,各个目标可以通过QT_QML_NO_QML_PREVIEW属性选择禁用预览,或者即使全局禁用了预览,也可以通过qt_add_qml_preview()重新启用预览。
© 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.