Qt 支持
Readme in English
Qt Support 扩展,支持创建/导入基于 CMake 的 Qt 项目,添加常见的 Qt 组件,如资源文件,翻译文件,类,设计器表单类等,Shift+F1
快捷键查看 Qt 文档,调用 Qt Designer,Qt Linguist 等工具。该扩展依赖于另外几个扩展:
- CMake Tools
ms-vscode.cmake-tools
- Kylin clangd
kylinideteam.kylin-clangd
- Kylin Native Debug
kylinideteam.kylin-debug
- CMake Intellisence
kylinideteam.cmake-intellisence
注意: 这些扩展仅仅在 Windows 上和 Linux 上测试过。Windows 上目前仅支持使用 mingw 构建的 Qt 进行调试。
注意事项
Qt 的安装位置: qt-support.qtInstallDirectories
扩展启动时会扫描 Qt 的默认安装位置,如果没有发现您安装的 Qt 时,可以设置该选项来指定 Qt 的安装位置。该位置需要设置为 Qt 的安装根目录,比如:D:\apps\Qt
, /home/user/.Qt
等。
依赖的软件
ninja-build
: 只有使用 ninja generator, CMake 才可以在所有的平台上都生成 clangd 需要的 compile_commands.json
文件,所以请首先安装该软件。
cmake
: 请安装 cmake 3.20 以上的版本
- 关于 Qt 文档:如果您的 Qt 是通过 Qt online installer 安装的,那么大概率文档已经安装。如果你在 linux 平台上,并且你使用的 Qt 是通过系统包管理器安装的。那么一般需要您额外安装 Qt 文档。
- 基于 apt 包管理器的系统:
sudo apt install qt5-doc qt5-doc-html
- 基于 yum/dnf 包管理器的系统:
sudo dnf install qt5-qtbase-doc qt5-qtdoc
- 其它软件
- 基于 apt 包管理器的系统:
sudo apt install build-essential ninja-build gdb cmake clangd qt5-default qttools5-dev-tools qttools5-dev qt5-qmake
- 基于 yum/dnf 包管理器的系统:
sudo dnf install gcc gcc-c++ make-devel ninja-build gdb cmake clang-tools-extra qt5-devel
- Windows 上,Qt 一般通过 online installer 安装。另外请自行安装
ninja-build cmake clangd
等工具,
关于 Qt Kit
扫描到 Qt 后,会在系统的缓存中生成 qt-kits.json 文件。CMake Tools 工具会读取该配置文件,并在 CMake Tools 扩展的 Kit 列表中显示,方便选择不同的 Qt 版本。该扩展提供的 Qt Kit,均以 [Qt Support]
开头。同时,该扩展在状态栏的左侧也提供了用于选择 Qt Kit 的按钮。
关于调试和运行
由于 CMake Tools 的调试功能依赖于 C/Cpp Tools,该扩展隐藏了 CMake Tools 的调试和运行功能,在状态栏提供了自己的调试和运行按钮。可通过状态栏的调试和运行按钮来调试和运行 Qt 程序。本扩展提供的调试和运行按钮的描述文本中有 (Qt Support)
字样。
调试插件目前使用的 kylinideteam.debug
,暂不支持 Windows 上的 MSVC 编译器以及 mingw。您也可以直接到该插件的仓库提问题或者做贡献:
特性
该扩展提供以下特性
- Qt 项目创建
- 导入基于 CMake 的 Qt 项目
- 添加 Qt 项目文件
- Designer Form Class
- Designer Form
- C++ class
- Translation
- Resource
Shift + F1
快捷键查看 Qt 的文档
- qrc 资源编辑器
- 使用 Qt Designer 打开 ui 文件
- 使用 Qt Linguist 打开 ts 文件
- 使用 Qt Creator 打开项目
- 使用 Visual Studio 打开项目
创建和导入项目
可以通过以下四种方式使用创建/导入项目的功能:
- 在命令面板中搜索命令
Qt Support: Create Qt Project...
- 在没有打开文件夹的情况下,按下
Ctrl + Shift + E
打开资源管理器,在欢迎视图中点击 Create Qt Project
按钮
- 在已经打开文件夹的情况下,资源管理器的右键菜单中有
Create Qt Project
选项
- 点击文件菜单 > 新建文件,在出现的 Quick Pick 中选择
创建 Qt 项目
添加 Qt 组件
在已经打开 Qt 项目的情况下,按下快捷键 Ctrl + shift + E
,在 Kylin-IDE 的资源管理器中点击鼠标右键,弹出的右键菜单中有 为 Qt 项目添加新文件
的上下文菜单。选择相应的子菜单就可以向项目中添加相关类型的文件。
Shift + F1
快捷键查看 Qt 的文档
当选择 Qt Kit 之后,打开 C++ 文件,将光标放置于想要查看文档的函数,类,方法名上面,按下 Shift + F1
快捷键,就会显示对应符号的文档。体验类似于 Qt Creator 的 F1 查看文档功能。如果该功能不可用,请尝试以下方法:
- 鼠标放置在函数名上之后,按下
Ctrl + Shift + p
打开命令面板,搜索命令 Qt Support: Show symbol documentation under cursor
, 并执行
- 如果上面的方法可行,请检查快捷键配置,查看是否时快捷键冲突,并设置为想要的快捷键
Qt 资源编辑器
该扩展提供了一个 Qt 资源编辑器,可以方便的编辑 Qt 的资源文件。当点击 .qrc 文件时,Kylin-IDE 默认会使用该扩展提供的 Qt 资源编辑器来打开 .qrc 文件。
打开外部工具
可以调用 Qt Designer 打开 .ui 文件,调用 Qt Linguist 打开 .ts 文件。有几种方式可以调用相关的命令:
- 在 Kylin-IDE 资源管理器中鼠标右键点击相应类型的文件,在右键菜单中会有相关的命令
- 当 .ui / .ts 文件处于打开状态时,在编辑器的标题栏中会有相关的按钮
- 当 .ts 文件处于打开状态时,在编辑器的上下文菜单中也会有相关的按钮
- 点击 .ui 文件后,会显示一个 webview,webview 中有一个按钮,点击按钮可以打开 Qt Designer
使用其它 ide 打开项目
可以使用 Qt Creator 和 Visual Studio (仅支持 Windows)打开项目,使用 Visual Studio 打开项目时,会自动生成 Visual Studio 所需的 CMakeSettings.json 文件,可以直接在 Visual Studio 中直接运行,调试基于 CMake 的 Qt 应用程序。
按下快捷键 Ctrl + shift + p
打开命令面板,搜索关键字 Qt Support: Open project in
,可以看到相关的命令。
问题反馈
如果遇到任何问题,请前往 Gitee 反馈问题。
Qt Support
中文说明
Qt Support extension, supports creating/importing CMake-based Qt projects, adding common Qt components such as resource files, translation files, classes, designer form classes, etc. Use the Shift+F1
shortcut to view Qt documentation, run Qt Designer, Qt Linguist, and other tools. This extension depends on several other extensions:
- CMake Tools
ms-vscode.cmake-tools
- Kylin clangd
kylinideteam.kylin-clangd
- Kylin Native Debug
kylinideteam.kylin-debug
- CMake Intellisense
kylinideteam.cmake-intellisence
Note: These extensions have only been tested on Windows and Linux. Currently, only Qt built with mingw is supported for debugging on Windows.
Notes
Qt installation location: qt-support.qtInstallDirectories
The extension will scan the default installation location of Qt at startup. If your installed Qt is not found, you can set this option to specify the Qt installation location. This location should be set to the root directory of the Qt installation, such as D:\apps\Qt
, /home/user/.Qt
, etc.
Required software
ninja-build
: Only with the ninja generator can CMake generate the compile_commands.json
file needed by clangd on all platforms, so please install this software first.
cmake
: Please install version 3.20 or higher of CMake.
- About Qt documentation: If your Qt is installed via the Qt online installer, the documentation is likely already installed. If you are on a Linux platform and your Qt is installed via the system package manager, you generally need to install the Qt documentation separately.
- For systems based on the apt package manager:
sudo apt install qt5-doc qt5-doc-html
- For systems based on the yum/dnf package manager:
sudo dnf install qt5-qtbase-doc qt5-qtdoc
- Other software
- For systems based on the apt package manager:
sudo apt install build-essential ninja-build gdb cmake clangd qt5-default qttools5-dev-tools qttools5-dev qt5-qmake
- For systems based on the yum/dnf package manager:
sudo dnf install gcc gcc-c++ make-devel ninja-build gdb cmake clang-tools-extra qt5-devel
- On Windows, Qt is generally installed via the online installer. Additionally, please install tools like
ninja-build cmake clangd
yourself.
About Qt Kit
After scanning Qt, a qt-kits.json
file will be generated in the system cache. The CMake Tools extension will read this configuration file and display it in the Kit list of the CMake Tools extension, making it easy to select different versions of Qt. The Qt Kits provided by this extension are prefixed with [Qt Support]
. Additionally, this extension provides a button on the left side of the status bar for selecting Qt Kits.
About debugging and running
Since the debugging function of CMake Tools depends on C/Cpp Tools, this extension hides the debugging and running functions of CMake Tools and provides its own debugging and running buttons in the status bar. You can debug and run Qt programs through the debugging and running buttons in the status bar. The description text of the debugging and running buttons provided by this extension includes (Qt Support)
.
The current debugging plugin used is kylinideteam.debug
, which does not support the MSVC compiler and mingw on Windows. You can also go directly to the plugin's repository to report issues or contribute:
Features
This extension provides the following features:
- Qt project creation
- Import CMake-based Qt projects
- Add Qt project files
- Designer Form Class
- Designer Form
- C++ class
- Translation
- Resource
Shift + F1
shortcut to view Qt documentation
- qrc resource editor
- Open .ui files with Qt Designer
- Open .ts files with Qt Linguist
- Open projects with Qt Creator
- Open projects with Visual Studio
Create and import projects
You can use the create/import project feature in the following four ways:
- Search for the command
Qt Support: Create Qt Project...
in the command palette
- When no folder is open, press
Ctrl + Shift + E
to open the explorer, and click the Create Qt Project
button in the welcome view
- When a folder is open, there is a
Create Qt Project
option in the right-click menu of the explorer
- Click the File menu > New File, and select
Create Qt Project
in the Quick Pick that appears
Add Qt components
When a Qt project is open, press Ctrl + Shift + E
, right-click in the explorer of Kylin-IDE, and there will be a context menu Add new file to Qt project
. Select the corresponding submenu to add the related type of file to the project.
Shift + F1
shortcut to view Qt documentation
After selecting the Qt Kit, open a C++ file, place the cursor over the function, class, or method name you want to view the documentation for, and press the Shift + F1
shortcut to display the documentation for the corresponding symbol. The experience is similar to the F1 documentation view feature in Qt Creator. If this feature is unavailable, try the following methods:
- After placing the mouse over the function name, press
Ctrl + Shift + p
to open the command palette, search for the command Qt Support: Show symbol documentation under cursor
, and execute it.
- If the above method works, check the shortcut key configuration to see if there is a shortcut key conflict, and set it to the desired shortcut key.
Qt resource editor
This extension provides a Qt resource editor that makes it easy to edit Qt resource files. When you click on a .qrc file, Kylin-IDE will use the Qt resource editor provided by this extension to open the .qrc file by default.
You can call Qt Designer to open .ui files and call Qt Linguist to open .ts files. There are several ways to call the relevant commands:
- Right-click the corresponding type of file in the Kylin-IDE explorer, and there will be related commands in the right-click menu.
- When a .ui / .ts file is open, there will be related buttons in the editor's title bar.
- When a .ts file is open, there will also be related buttons in the editor's context menu.
- After clicking on a .ui file, a webview will be displayed, and there will be a button in the webview. Clicking the button will open Qt Designer.
Open projects with other IDEs
You can open projects with Qt Creator and Visual Studio (Windows only). When opening a project with Visual Studio, a CMakeSettings.json
file required by Visual Studio will be automatically generated, allowing you to directly run and debug CMake-based Qt applications in Visual Studio.
Press Ctrl + Shift + p
to open the command palette, search for the keyword Qt Support: Open project in
, and you will see the relevant commands.
Feedback
If you encounter any issues, please go to Gitee to provide feedback.