使用 vcpkg 在 Windows 下安装的示例

你可以在 Windows 下使用 vcpkg 安装 Protobuf 和 gRPC软件包。

注意: 作为替代方案,你可以手动构建 Protobuf 和gRPC 软件包。可以分别找到ProtobufgRPC的构建说明。

Windows 安装前提条件:

vcpkg 是一个跨平台的 C/C++ 包管理器。您可以使用vcpkg 安装 Protobuf、gRPC 及其依赖库:

.\vcpkg.exe install protobuf protobuf:x64-windows
.\vcpkg.exe install grpc:x64-windows

注意: 我们建议使用 Manifest 模式。该模式使用声明式 JSON 文件来描述项目的元数据。Manifest 文件必须以 vcpkg.json 命名。

最后,你可以利用支持 Protobuf 和gRPC 的 Qt Protobuf 来构建和执行基于 Qt 的项目。例如,从已安装的 Qt 版本运行Magic 8 Ball。该示例需要安装这两个软件包,因为Magic 8 Ball 在应用程序的服务器部分使用了本地 C++ 源代码生成器插件。启动Magic 8 Ball 示例需要以下步骤:

  • Examples 部分找到Magic 8 Ball

    显示 Qt Creator 主页菜单的截图,在示例部分,在搜索栏中输入 "magic"(魔法)后,会显示带有此名称的示例

  • 从 Qt-creator 配置设置中选择基于 MSVC 的构建工具包:

    显示构建项目的 msvc 工具包的截图

  • Initial Configuration 设置块内的CMAKE_PREFIX_PATH 环境变量中添加已安装的 Protobuf 和gRPC 软件包的路径:

    显示使用 msvc 工具包的 Qt Creator 的构建选项的截图

  • 构建并运行。

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