注册 Qt 安装
要使用 Qt 进行开发,您至少需要一个 Qt 版本。您可以通过多种方式安装 Qt:
- 使用Qt Online Installer
- 使用包管理器
- 从源代码编译 Qt
自动注册
VS Code 的 Qt 扩展会检查默认路径下是否存在 Qt 安装文件夹,并提示将其保存到Qt 设置中。选择“Use ”以保存该文件夹并注册其中的 Qt 版本。
此外,如果您通过vcpkg 安装 Qt,VS Code 的 Qt 扩展会自动检测到该安装,并提供创建相应的 CMake 套件。随后,它将使用Qt Widgets Designer 等工具,并采用vcpkg 中的路径。请在launch.json文件中设置环境变量QT_QPA_PLATFORM_PLUGIN_PATH 和QML_IMPORT_PATH 以配置 Qt 安装。
VS Code 的 Qt 扩展会在 VS Code 启动时扫描并更新套件。如果您手动管理套件,或者将cmake-kits.json 套件配置文件置于版本控制之下,可以在 Qt 设置中关闭此功能。
如果您未将 Qt 安装在默认路径下,或者系统无法自动检测到vcpkg 安装,请按照以下各节所述注册您的 Qt 版本。
要添加 Qt 安装路径,请转至“Command Palette ”,然后选择“Open Qt settings ”。
Qt Online Installer installations
若要将使用Qt Online Installer 安装的Qt注册到默认路径以外的文件夹中:
- 转到“Command Palette ”,然后选择“Qt: Register Qt installation ”。
- 选择您安装 Qt 的文件夹,然后选择Select the Qt installation path 。
该命令会为每个已安装的 Qt 版本创建 CMake 套件。

其他安装方式
若要注册通过软件包管理器安装或从源代码编译的 Qt:
- 转到Command Palette ,然后选择Qt: Register Qt (qtpaths or qmake) 。
- 选择“
qmake”或“qtpaths”可执行文件,然后选择“Select ”。
该命令将为 qtpaths 生成一个 CMake 套件。
扫描 Qt 套件
如果缺少某些 Qt CMake 套件,请转到Command Palette 并选择Qt: Scan for Qt kits 。
要在状态栏上显示已注册的套件,请转到“Command Palette ”,然后选择“Qt: Set the recommended Qt Extension settings ”。
使用 CMake 预设
除了将 Qt 安装注册为 CMake 套件外,您还可以使用CMakePresets.json 文件来设置 Qt 安装的路径。
另请参阅 Qt 设置和使用 CMake 预设进行构建。
© 2026 The Qt Company Ltd. 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.