创建Qt Quick 用户界面原型

Qt Quick UI 原型项目适用于测试或原型设计用户界面,或者例如专门用于 QML 编辑的独立项目。您无法将其用于应用程序开发,因为它们不具备:

  • C++ 代码
  • 资源文件(.qrc
  • 将应用程序部署到设备所需的代码

有关如何将Qt Quick UI原型项目转换为Qt Quick 应用程序项目的更多信息,请参阅《将UI项目转换为应用程序》。

要创建Qt Quick UI 原型项目:

  1. 转至File >New Project >Other Project > Qt Quick UI Prototype
  2. 选择“Choose ”以打开“Project Location ”对话框。
  3. 在“Name ”中,输入应用程序的名称。
  4. 在“Create in ”中,输入项目文件的路径。选择“Use as default project location ”以默认在此文件夹中创建新项目。
  5. 选择“Next ”(或 macOS 上的“Continue ”),以打开“Define Project Details ”对话框。
  6. 选择 Create a project that you can open in Qt Quick Designer 以使项目与Qt Quick Designer兼容。
  7. 选择 Use Qt Virtual Keyboard 以添加对 Qt Virtual Keyboard

    注意:如果您在 安装 Qt XML 时未安装Qt Virtual Keyboard 模块,在尝试打开main.qml 时会出现错误信息。

  8. 选择“Next ”以打开“Kit Selection ”对话框。
  9. 为要构建应用程序的平台选择套件

    注意: 只有在“Preferences ”>“Kits ”中指定过的套件 才会显示在列表中。

  10. 选择“Next ”以打开“Project Management ”对话框。
  11. 检查项目设置,然后选择“Finish ”(Windows 和 Linux 系统)或“Done ”(macOS 系统)以创建项目。

Qt Creator 将生成以下文件:

  • .qmlproject 项目文件定义了项目文件夹中的所有 QML、JavaScript 和图像文件均属于该项目。因此,您无需逐一列出项目中的所有文件。
  • .qml 文件定义了一个 UI 项,例如一个组件或整个应用程序的 UI。
  • Screen01.ui.qml 该文件使用 Rectangle 类型的实例(用于构成背景)、Button 以及显示文本的 Text 组件,定义了一个自定义 QML 类型。若选择 Create a project that you can open in Qt Quick Designer

要在应用程序中使用 JavaScript 和图像文件,请将它们复制到项目文件夹中。

另请参阅 “创建项目”“操作指南:设计Qt Quick 用户界面”“操作指南:管理套件”“设计Qt Quick 用户界面”Qt Quick 用户界面设计”以及“指定Qt Quick 用户界面原型运行设置”

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.