将用户界面项目转换为应用程序
Qt Quick 用户界面原型项目可用于创建用户界面。要将它们用于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 安装中不可用。要在Qt Creator 中使用它们,必须手动安装模块。
例如
- 克隆模块库。
git clone https://code.qt.io/qt-labs/qtquickdesigner-components.git
- 安装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/。
处理大型数据文件
用户界面中使用的 Graphical 资产(如图像、特效或 3D 场景)是导致用户界面性能问题的典型原因。如果尝试在.qrc 文件中包含大型资产文件(如 100MB 的 3D 模型或 64MB 的纹理),以便将其编译为二进制文件,那么即使是构建应用程序也需要大量内存。
首先尝试优化资产,如优化设计中所述。
大型资产应直接从文件系统或动态使用 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.