创建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 XML 时未安装Qt Virtual Keyboard 模块,在尝试打开Main.qml 进行编辑时会出现错误信息。您可以使用 Qt Online Installer 来安装Qt Virtual Keyboard

  7. Minimum required Qt version 中选择用于开发的Qt版本。Qt版本决定了Qml文件中使用的Qt Quick 导入内容。
  8. 对于 Qt 6.10 之前的版本,请选择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 这将生成一个名为Main.qml 的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.