安装 qt6
安装qt6: https://mirrors.tuna.tsinghua.edu.cn/qt/official_releases/online_installers/
查看当前最长支持周期版本(6.8):https://doc.qt.io/qt-6/qt-releases.html
使用国内镜像安装:
.\qt-online-installer-windows-x64-online.exe --mirror https://mirrors.ustc.edu.cn/qtproject
自定义安装,如果需要添加或移除组件,可通过以下方式操作: 打开 Qt Maintenance Tool(维护工具)。登录后选择“添加或移除组件”,根据需求调整:
- Qt Creator:不选插件开发
- Qt Installer Framework
- Extensions:选择llvm-mingw 和源码
- Qt for Development:选择 6.11 ,llvm-mingw 和源码
- Qt Design Studio: 选择最新版本
记录 Qt 的安装路径(如: C:\Qt\6.11.1\llvm-mingw_64),将 C:\Qt\6.11.1\llvm-mingw_64\bin ,C:\Qt\Tools\CMake_64\bin\ ,C:\Qt\Tools\QtCreator\bin 加入系统path
创建环境变量 CMAKE_PREFIX_PATH, 值为 C:\Qt\6.11.1\llvm-mingw_64\lib\cmake
安装 visual studio 2026社区版
https://visualstudio.microsoft.com/zh-hans/
选择桌面c++开发(默认安装,不选择clang相关组件) ,修改产品安装位置安装:C:\VisualStudio\18\Community
vs 安装插件: Qt VS Tools for Visual Studio 2022 and 2026。(根据提示关闭vs自动安装插件)
vs 配置qt版本:扩展,qt vs tools,qt versions,location选 C:\Qt\6.8.3\llvm-mingw_64\bin\qmake.exe , 可能无法添加,
**创建 qt quick项目,不要勾选 Enable PCH support, 可能报错 C1014 包含文件太多: 深度 = 1024,Build System 选cmake project for qt
打包:
C:\Qt\6.8.3\msvc2022_64\bin\windeployqt.exe xxx.exe --qmldir xxx\QtQuickProject
cmake项目
设置,选项,cmake,常规,cmake配置文件:始终使用cmake预设
新建cmake项目,勾选将解决方案和项目放在同一目录中,
cmake项目默认源代码:
CMakeLists.txt
# CMakeList.txt: CMakeProject1 的 CMake 项目,在此处包括源代码并定义
# 项目特定的逻辑。
#
cmake_minimum_required (VERSION 3.10)
# 如果支持,请为 MSVC 编译器启用热重载。
if (POLICY CMP0141)
cmake_policy(SET CMP0141 NEW)
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>")
endif()
project ("CMakeProject1")
# 将源代码添加到此项目的可执行文件。
add_executable (CMakeProject1 "CMakeProject1.cpp" "CMakeProject1.h")
if (CMAKE_VERSION VERSION_GREATER 3.12)
set_property(TARGET CMakeProject1 PROPERTY CXX_STANDARD 20)
endif()
# TODO: 如有需要,请添加测试并安装目标。
CMakePresets.json
{
"version": 3,
"configurePresets": [
{
"name": "windows-base",
"hidden": true,
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"cacheVariables": {
"CMAKE_C_COMPILER": "cl.exe",
"CMAKE_CXX_COMPILER": "cl.exe"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "x64-debug",
"displayName": "x64 Debug",
"inherits": "windows-base",
"architecture": {
"value": "x64",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_PROJECT_TOP_LEVEL_INCLUDES": "$env{VSINSTALLDIR}Common7/IDE/CommonExtensions/Microsoft/CMake/cmake/Microsoft/SegmentHeap.cmake"
}
},
{
"name": "x64-release",
"displayName": "x64 Release",
"inherits": "x64-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_PROJECT_TOP_LEVEL_INCLUDES": "$env{VSINSTALLDIR}Common7/IDE/CommonExtensions/Microsoft/CMake/cmake/Microsoft/SegmentHeap.cmake"
}
},
{
"name": "x86-debug",
"displayName": "x86 Debug",
"inherits": "windows-base",
"architecture": {
"value": "x86",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_PROJECT_TOP_LEVEL_INCLUDES": "$env{VSINSTALLDIR}Common7/IDE/CommonExtensions/Microsoft/CMake/cmake/Microsoft/SegmentHeap.cmake"
}
},
{
"name": "x86-release",
"displayName": "x86 Release",
"inherits": "x86-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_PROJECT_TOP_LEVEL_INCLUDES": "$env{VSINSTALLDIR}Common7/IDE/CommonExtensions/Microsoft/CMake/cmake/Microsoft/SegmentHeap.cmake"
}
}
]
}
CMakeProject1.cpp
// CMakeProject1.cpp: 定义应用程序的入口点。
//
#include "CMakeProject1.h"
using namespace std;
int main()
{
cout << "Hello CMake." << endl;
return 0;
}
CMakeProject1.h
// CMakeProject1.h: 标准系统包含文件的包含文件
// 或项目特定的包含文件。
#pragma once
#include <iostream>
// TODO: 在此处引用程序需要的其他标头。
vcpkg
下载: https://github.com/microsoft/vcpkg
解压到某目录,如 C:\vcpkg-2026.05.25,进入vcpkg目录,启动power shell(建议),执行
.\bootstrap-vcpkg.bat -disableMetrics
Downloading https://github.com/microsoft/vcpkg-tool/releases/download/2026-04-08/vcpkg.exe -> C:\vcpkg-2026.05.25\vcpkg.exe... done.
Validating signature... done.
vcpkg package management program version 2026-04-08-e0612b42ce44e55a0e630f2ee9d3c533a63d8bc1
See LICENSE.txt for license information.
Telemetry
---------
vcpkg collects usage data in order to help us improve your experience.
The data collected by Microsoft is anonymous.
You can opt-out of telemetry by re-running the bootstrap-vcpkg script with -disableMetrics,
passing --disable-metrics to vcpkg on the command line,
or by setting the VCPKG_DISABLE_METRICS environment variable.
Read more about vcpkg telemetry at docs/about/privacy.md
顺利完成后,目录下会出现vcpkg.exe文件。(也可以直接下载该exe放入该目录)
将 vcpkg 与开发环境(例如 Visual Studio 和 MSBuild)进行全局集成,使 vcpkg 安装的库能自动被项目识别和使用
.\vcpkg.exe integrate install
Applied user-wide integration for this vcpkg root.
CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg-2026.05.25/scripts/buildsystems/vcpkg.cmake"
All MSBuild C++ projects can now #include any installed libraries. Linking will be handled automatically. Installing new libraries will make them instantly available.
.\bootstrap-vcpkg.bat -disableMetrics
Downloading https://github.com/microsoft/vcpkg-tool/releases/download/2026-04-08/vcpkg.exe -> C:\vcpkg-2026.05.25\vcpkg.exe... done.
Validating signature... done.
vcpkg package management program version 2026-04-08-e0612b42ce44e55a0e630f2ee9d3c533a63d8bc1
See LICENSE.txt for license information.
示例,搜索和安装boost库
.\vcpkg.exe search boost
.\vcpkg.exe install boost
有些文件下载比较慢,可以用其他工具下载放入 C:\vcpkg-2026.05.25\downloads 目录重新执行安装boost 的命令
cmake配置,参考: https://www.cnblogs.com/quantoublog/articles/18820438