创建Qt Quick 应用程序

您可以创建包含 QML 和 C++ 代码的Qt Quick 应用程序。构建应用程序并将其部署到桌面、嵌入式和移动目标平台。

创建Qt Quick 应用程序项目:

  1. 转到File >New Project >Application (Qt) > 。 Qt Quick Application.

    新项目对话框

    注: 要使用qmake作为构建系统、使用 Qt 5 进行开发或为应用程序添加翻译,请选择 Qt Quick Application (compat).

  2. 选择Choose ,打开Project Location 对话框。
  3. Name 中,输入项目名称。请记住,以后不能轻易更改项目名称。
  4. Create in 中,输入项目文件的路径。选择Use as default project location 默认在此文件夹中创建新项目。以后可以移动项目文件夹,不会出现问题。
  5. 选择Next 打开Define Project Details 对话框。

    定义项目详细信息对话框

  6. 选择 Use Qt Virtual Keyboard以在应用程序中添加对 Qt Virtual Keyboard的支持。

    注意: 如果在安装 Qt 时没有安装Qt Virtual Keyboard 模块,则在尝试打开Main.qml 进行编辑时会出现错误信息。您可以使用 Qt Online Installer来安装Qt Virtual Keyboard

  7. Minimum required Qt version 中选择要使用的 Qt 版本进行开发。Qt 版本决定了 QML 文件中使用的Qt Quick 导入。
  8. 对于早于 6.10 的 Qt 版本,选择Set QT_QML_GENERATE_QMLLS_INI to ON in CMake 配置QML Language Server 。它提供代码自动补全功能,并在您编写 QML 代码时发出警告。
  9. 选择Next 打开Kit Selection 对话框。
  10. 为要构建应用程序的平台选择工具包

    注: 如果已在Preferences >Kits 中指定了工具包,则会列出这些工具包。有关详细信息,请参阅添加工具包管理工具包

  11. 选择Next 打开Project Management 对话框。
  12. 查看项目设置,然后选择Finish (在 Windows 和 Linux 上)或Done (在 macOS 上)创建项目。

Qt Creator 创建一个 QML 文件Main.qml ,您可以在Edit 模式下修改该文件。

另请参阅 如何设计Qt Quick UI为项目配置语言服务器教程:移动应用程序教程:Qt Quick 和 Python教程: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.