Qt UI Tools
Qt UI Tools 模块允许您在运行时实例化Qt Widgets Designer 表单(UI文件)。这是使用User Interface Compiler (uic)将表单编译为代码的一种替代方案。它使您能够调整用户界面,而无需重新编译或重启应用程序。
UI 文件可从多种位置加载,例如应用程序的资源、本地文件系统或受信任的网络源。定位到文件后,请使用QUiLoader 类及其QUiLoader::load() 函数来实例化该文件。
使用模块
要使用 Qt 模块的 C++ API,需要将模块库链接到项目中,既可以直接链接,也可以通过其他依赖项间接链接。包括CMake和qmake 在内的多种构建工具都为此提供了专门的支持。
使用 CMake 构建
使用find_package() 命令在Qt6 软件包中定位所需的模块组件:
find_package(Qt6 REQUIRED COMPONENTS UiTools)
target_link_libraries(mytarget PRIVATE Qt6::UiTools)更多详细信息,请参阅“使用 CMake 构建”概述。
使用 qmake 构建
要配置模块以便使用 qmake 进行构建,请在项目的 .pro 文件中将该模块作为QT 变量的值添加:
QT += uitools安全注意事项
仅从可信来源(如Qt 资源系统)加载表单。从未经信任的来源加载.ui 文件可能会导致应用程序面临安全威胁,例如拒绝服务攻击、用户界面欺骗或意外加载插件。
示例
参考
许可证
Qt UI Tools Qt 由The Qt Company 提供商业许可。此外,它还提供自由软件许可。自 Qt 6.0 起,这些自由软件许可包括GNU 较少通用公共许可证第 3 版或 GNU 通用公共许可证第 2 版。更多详细信息请参阅Qt 许可。
© 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.