生成 CMake 配置文件
开发 QML 项目(.qmlproject )可用于创建用户界面。若要使用这些项目通过Qt Creator 或其他开发工具进行应用程序开发,您需要添加:
- 一个
CMakeLists.txt项目配置文件 - C++ 代码(
.cpp) - 资源文件
- 将应用程序部署到设备所需的代码
有关集成 QML 和 C++ 的更多信息,请参阅《Qt:概述——QML 与 C++ 的集成》。
使用 CMake 构建Qt Quick 应用程序
Qt Creator 项目向导模板可创建可通过 CMake 构建的项目。CMake 是一款旨在简化跨平台开发项目构建流程的工具。它会自动生成构建系统,例如 Makefile 和 Ninja 文件。
有关使用 CMake 构建 Qt 应用程序的更多信息,请参阅:
为 QML 模块创建 CMakeList.txt 文件
Figma to Qt 会生成一个CMakeLists.txt 文件,其中包含针对每个已下载QML模块的qt_add_qml_module()调用。您可以在项目的CMakeLists.txt 主文件中包含这些文件。
要为 QML 模块创建 CMake 配置文件:
- 在插件中,转到“
”(Settings )>“Code ”。
在插件的“设置”页面中,通过“代码设置”生成 CMakeLists.txt 文件。
- 选择“Generate CMakeLists.txt ”。
- 选择“
”(Download ),以将CMakeLists.txt文件包含在下载的包中。
CMakeList.txt 文件示例
例如,对于使用设计令牌的设计,Figma to Qt 会生成以下CMakeLists.txt 文件:
qt_add_qml_module(DesignTokens
URI DesignTokens
QML_FILES
MainScreen.qml
Button.qml
RESOURCES
assets/icon.png
assets/icon@2x.png
)文件使用示例
在项目的主CMakeLists.txt 文件中,使用add_subdirectory() 调用包含生成的模块,并使用target_link_libraries() 调用链接到您的应用程序:
make_minimum_required(VERSION 3.16)
project(MyApp LANGUAGES CXX)
find_package(Qt6 REQUIRED COMPONENTS Quick)
# Include the generated module
add_subdirectory(DesignTokens)
# Link to your application
qt_add_executable(MyApp main.cpp)
target_link_libraries(MyApp PRIVATE DesignTokens)另请参阅 “将变量转换为设计令牌”和“下载转换后的设计”。
© 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.