qt_wrap_ui
用于生成 .ui 文件的源代码。
该命令定义在Qt6 包的Widgets 组件中。使用以下命令加载该包:
find_package(Qt6 REQUIRED COMPONENTS Widgets)用法
qt_wrap_ui(<VAR> ui_file1 [ui_file2 ...]
[OPTIONS ...])如果禁用了无版本号的命令,请改用qt6_wrap_ui() 。它支持与本命令相同的参数集。
描述
为给定的.ui 文件创建调用User Interface Compiler (uic)的规则。对于每个输入文件,将在构建目录中生成一个头文件。生成的头文件的路径将被添加到<VAR> 中。
注意:这是一个 低级宏。有关使用uic 处理.ui 文件的更便捷方法,请参阅CMake AUTOUIC文档。
自 6.8 起:
注意: qt_add_ui()是处理.ui 文件的推荐方法。
选项
您可以设置应添加到uic 调用中的额外OPTIONS 。可在uic 文档中查阅可用选项。
示例
set(SOURCES mainwindow.cpp main.cpp)
qt_wrap_ui(SOURCES mainwindow.ui)
qt_add_executable(myapp ${SOURCES})© 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.