本页内容

适用于 Windows 的 Qt - Windows 应用程序 SDK

配置

要在 Qt 应用程序中使用Windows App SDK,请配置 SDK 路径。

使用方法Qt Creator

要在Qt Creator 中配置Windows App SDK,请转至“Preferences ” > “SDKs ”。

\QC SDK 首选项。

有关更多信息,请参阅Qt Creator 文档。

通过命令行

  1. 进入一个空目录。

    示例:

    mkdir C:\Dev\wasdk
    cd C:\Dev\wasdk
  2. 将NuGet下载到该目录中。

    例如,若要通过 PowerShell 从命令行下载:

    powershell.exe -Command "& {Invoke-WebRequest https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -OutFile nuget.exe}"
  3. 使用 NuGet 下载 Windows App SDK。
    nuget.exe install Microsoft.WindowsAppSDK -OutputDirectory ./
  4. 将环境变量 `WIN_APP_SDK_ROOT ` 设置为 Windows App SDK 目录,通常为 `Microsoft.WindowsAppSDK.{Version}`。

    例如,使用命令行:

    cd Microsoft.WindowsAppSDK.*
    set WIN_APP_SDK_ROOT=%cd%
    setX WIN_APP_SDK_ROOT %cd%

在 Qt 应用程序中使用 Windows App SDK

在项目的 CMake 文件中调用qt_add_win_app_sdk(ProjectName) CMake 函数。将ProjectName替换为您的项目名称。

使用条件确保仅针对 MSVC 进行构建:

if (MSVC)
    qt_add_win_app_sdk(ProjectName)
endif()

© 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.