本页内容

将 UI 项目转换为应用程序

Qt Quick UI原型项目可用于创建用户界面。若要在Qt Creator 中将其用于应用程序开发,您需要添加:

  • 一个CMakeLists.txt 项目配置文件
  • C++代码(.cpp
  • 资源文件
  • 将应用程序部署到设备所需的代码

有关集成 QML 和 C++ 的更多信息,请参阅《概述 - QML 与 C++ 集成》。

使用 CMake 构建Qt Quick 应用程序

Qt Design Studio 项目向导模板可生成可通过 CMake 构建的项目。您可以在Qt Creator 中打开CMakeLists.txt 项目文件,以继续开发该项目。

向 Qt 安装中添加 Studio 组件

Qt Design Studio 中,您可以使用Qt Quick 的 Studio 组件,这些组件在 Qt XML 安装中默认不可用。要在Qt Creator 中使用它们,必须手动安装该模块。

例如:

  1. 克隆模块仓库。
    git clone https://code.qt.io/qt-labs/qtquickdesigner-components.git
  2. 安装Qt Quick Studio Components 模块。
    mkdir build
    cd build
    cmake -GNinja -DCMAKE_INSTALL_PREFIX=<path_to_qt_install_directory> <path_to_qtquickdesigner-components>
    cmake --build .
    cmake --install .

    注意:请将 <path_to_qt_install_directory><path_to_qtquickdesigner-components>替换 为您计算机上的实际路径。例如,/Qt/6.11.0/msvc2022_64../qtquickdesigner-components/

处理大型数据文件

UI 中使用的图形资源(如图像、特效或 3D 场景)是导致 UI 性能问题的典型原因。 如果您尝试将大型资源文件(例如 100 MB 的 3D 模型或 64 MB 的纹理)包含到.qrc 文件中以编译为二进制文件,即使只是构建应用程序,也会消耗大量内存。

首先请按照“优化设计”中的说明对资源进行优化。

大型资源应直接从文件系统加载,或通过 Qt 资源系统动态加载。有关更多信息,请参阅《Qt 资源系统》

另请参阅 《创建Qt Quick UI原型》、《如何设计Qt Quick UI》、 Qt Quick UI设计 以及《设计Qt Quick UI》。

Copyright © The Qt Company Ltd. and other contributors. 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.